#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int Min = pow(10, n - 1);
  if (n == 0) Min = 0;
  int Max = pow(10, n) - 1;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < (int)m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = Min; i <= Max; i++) {
    string str = to_string(i);
    bool ok = true;
    for (int j = 0; j < (int)m; j++) {
      if (str[s[j] - 1] != c[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
