#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long INF = 1e17;
long long dp[10005];
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
signed main(void) {
  long long N, M;
  cin >> N >> M;
  long long num[N];
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    num[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (num[N - s] == -1 || num[N - s] == c) {
      num[N - s] = c;
      if (s == 1 && c == 0 && N > 1) {
        ans = -1;
      }
    } else {
      ans = -1;
    }
  }
  if (ans != -1) {
    long long base = 1;
    for (int i = 0; i < N; i++) {
      if (i == N - 1) {
        if (num[i] > 0) {
          ans += base * num[i];
        } else if (num[i] == 0) {
          if (N == 1) {
            ans = 0;
          } else {
            ans = -1;
            break;
          }
        } else {
          ans += base;
        }
      } else {
        if (num[i] != -1) {
          ans += base * num[i];
        }
      }
      base *= 10;
    }
  }
  cout << ans << endl;
}
