#include <bits/stdc++.h>
using namespace std;
int getDigit(int n) {
  int d = 0;
  while (n) {
    n /= 10;
    d++;
  }
  return d;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (1000); i++) {
    int k = getDigit(i);
    if (k != n) continue;
    bool f = false;
    string str = to_string(i);
    for (int j = 0; j < (m); j++) {
      char ch = str[s[j] - 1];
      if ((int)(ch - '0') != c[j]) {
        f = true;
        break;
      }
    }
    if (f) continue;
    cout << i << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}
