#include <bits/stdc++.h>
using namespace std;
const long double PI = (acos(-1));
long long mpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a;
    a = a * a;
    n >>= 1;
  }
  return res;
}
int main() {
  int n, m, ans = 0;
  scanf("%d", &n), scanf("%d", &m);
  bool check = true;
  vector<int> s(m), c(m), x(n, -1);
  for (int i = 0; i < (int)(m); i++) scanf("%d", &s[i]), scanf("%d", &c[i]);
  for (int i = 0; i < (int)(m); i++) {
    if (x[s[i] - 1] == -1 || x[s[i] - 1] == c[i])
      x[s[i] - 1] = c[i];
    else
      check = false;
    if (!check) break;
  }
  for (int i = 0; i < (int)(n); i++) {
    if (x[i] == -1) {
      if (i == 0) ans += mpow(10, n - i - 1);
    } else {
      if (i == 0 && x[i] == 0) {
        if (n == 1) {
          ans = 0;
          break;
        }
        check = false;
      }
      ans += x[i] * mpow(10, n - i - 1);
    }
  }
  if (check)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
