#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> num(n + 1, 0);
  while (m--) {
    long long s, c;
    cin >> s >> c;
    if (num[s - 1] == 0 || num[s - 1] == c) {
      num[s - 1] = c;
    } else {
      cout << "-1";
      return 0;
    }
  }
  long long x = 0;
  long long count = 0;
  long long p = 0;
  for (long long i = 0; i < n; i++) {
    if (num[i] == 0 && x == 0) {
      x = 1;
    } else {
      p = (10 * p) + (num[i]);
      count++;
      x = 1;
    }
  }
  if (count == n) {
    cout << p;
  } else {
    cout << "-1";
  }
}
