#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = -1;
  cin >> n >> m;
  vector<int> s(n);
  vector<char> c(n);
  for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  for (int i = 0; i < 1000; ++i) {
    string str = to_string(i);
    bool flag = 1;
    for (int j = 0; j < m; ++j) {
      if (n > 1 and s[j] == 1 and c[j] == '0') {
        cout << "-1\n";
        return 0;
      }
      if (str[s[j] - 1] != c[j]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans << "\n";
}
