#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  string s;
  vector<pii> vec(m);
  for (int(i) = (0); (i) < (m); (i)++) {
    int s, c;
    cin >> s >> c;
    vec[i] = make_pair(s, c);
  }
  bool flag;
  for (int(i) = (pow(10, n - 1)); (i) < (pow(10, n)); (i)++) {
    s = to_string(i);
    flag = true;
    for (int(j) = (0); (j) < (m); (j)++) {
      if ((int)(s[vec[j].first - 1] - '0') != (vec[j].second)) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
