#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
signed main() {
  int n, m;
  cin >> n >> m;
  vi v(n), a(n);
  for (long long i = 0; i < (long long)(m); i++) cin >> v[i] >> a[i];
  for (long long i = 0; i < (long long)(1000); i++) {
    string s = to_string(i);
    if (s.size() != n) break;
    bool ok = true;
    for (long long j = 0; j < (long long)(m); j++) {
      int k = v[j] - 1;
      if (s[k] != (char)('0' + a[j])) {
        ok = false;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
