#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0 && n == 1) {
    cout << 0 << endl;
    return 0;
  } else if (m == 0) {
    cout << pow(10, n - 1) << endl;
    return 0;
  }
  int cnt = 0;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    if (m == 1 && c[i] == '0') {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    string i2 = to_string(i);
    for (int j = 0; j < m; j++) {
      if (i2[s[j] - 1] == c[j]) cnt++;
    }
    if (cnt == m) {
      cout << i << endl;
      return 0;
    }
    cnt = 0;
  }
  cout << -1 << endl;
}
