#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int S[m], C[m];
  for (int i = 0; i < m; ++i) {
    cin >> S[i] >> C[i];
    S[i]--;
  }
  for (int ans = 0; ans < 1000; ++ans) {
    string s = to_string(ans);
    if (s.length() != n) continue;
    bool ok = true;
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j == S[i] && (s[j] - '0') != C[i]) ok = false;
        if (ok) {
          cout << ans << endl;
          return 0;
        }
      }
    }
  }
  cout << -1;
  return 0;
}
