#include <bits/stdc++.h>
using namespace std;
long long inf = LLONG_MAX;
long double pi = M_PI;
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (long long i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (long long i = 0; i < 1000; i++) {
    string ans = to_string(i);
    if (ans.size() != n) continue;
    for (long long j = 0; j < m; j++) {
      if (ans[s[j] - 1] - '0' != c[j]) break;
      if (j == m - 1) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}
