#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main() {
  int n, m;
  cin >> n >> m;
  int c[n];
  for (int i = 0; i < n; ++i) c[i] = INF;
  int s, tmp;
  for (int i = 0; i < m; ++i) {
    cin >> s;
    cin >> tmp;
    if (c[s - 1] != INF && c[s - 1] != tmp) {
      cout << -1 << endl;
      return 0;
    }
    c[s - 1] = tmp;
  }
  if (c[0] == INF) c[0] = 1;
  for (int i = 0; i < n; ++i)
    if (c[i] == INF && i != 0) c[i] = 0;
  if (c[0] == 0) cout << -1 << endl;
  return 0;
  for (int i = 0; i < n; ++i) cout << c[i];
  cout << endl;
  return 0;
}
