#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  int ans = -1;
  for (int i = 1; i < (1000); i++) {
    string si = to_string(i);
    bool check = 1;
    for (auto i = 0; i < m; ++i) {
      int ci = si[s[i] - 1] - '0';
      if (ci != c[i]) {
        check = 0;
        break;
      }
    }
    if (check) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
