#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  long long l = 1;
  long long r = 10;
  for (long long i = 1; i < n; i++) {
    l *= 10;
    r *= 10;
  }
  long long ll[10] = {};
  memset(ll, -1, sizeof(ll));
  long long s[10], c[10];
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (long long i = 0; i < m; i++) {
    if (ll[s[i]] != -1 && ll[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    ll[s[i]] = c[i];
  }
  for (long long i = l; i < r; i++) {
    string num = to_string(i);
    long long j;
    for (j = 0; j < n; j++) {
      if (ll[j] != -1 && ll[j] != num[j] - '0') {
        break;
      }
    }
    if (j == n) {
      cout << num << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
