#include <bits/stdc++.h>
using namespace std;
long long INF = LLONG_MAX;
int con[6], con1[6];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, pos, val;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> con[i] >> con1[i];
    con[i]--;
  }
  for (int i = (n == 1 ? 0 : (n == 2 ? 10 : 100));
       i < (n == 1 ? 9 : (n == 2 ? 99 : 999)); i++) {
    string str = to_string(i);
    bool ok = 1;
    for (int j = 0; j < m; j++) {
      if (str[con[j]] - '0' != con1[i]) ok = 0;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
