#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long inf64 = 1e18;
const long long MOD = inf + 7;
signed main() {
  ios::sync_with_stdio(false), cin.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  long long a[m][2];
  for (long long i = 0; i < (long long)m; i++) cin >> a[i][0] >> a[i][1];
  for (long long i = 1; i <= 10001; i++) {
    string s = to_string(i);
    if (s.length() != n) continue;
    long long ok = 1;
    for (long long j = 0; j < m; j++) {
      if (s[a[j][0] - 1] - '0' != a[j][1]) ok = 0;
    }
    if (ok) {
      cout << i;
      return 0;
    }
  }
  cout << "-1";
}
