#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 4e5 + 10;
void raushan_kumar() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> v(m);
  for (long long i = 0, iend = m; i < iend; i++) {
    cin >> v[i].first >> v[i].second;
  }
  long long ans = -1;
  for (long long i = 0, iend = 1001; i < iend; i++) {
    long long flag = 0;
    string t = to_string(i);
    for (long long j = 0, jend = m; j < jend; j++) {
      if (t[v[j].first - 1] != (char)(v[j].second + '0')) {
        flag = 1;
      }
    }
    if (!flag) {
      ans = i;
      break;
      ;
    }
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    raushan_kumar();
  }
}
