#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int n, m;
  int x;
  int ret = -1;
  cin >> n >> m;
  vector<P> p(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  for (x = 0; x < 1000; x++) {
    string number = to_string(x);
    int n_keta = number.length();
    if (x / 100 == 0) number = "0" + number;
    if (x / 10 == 0) number = "0" + number;
    if (m == 0) {
      if (n_keta == n) {
        ret = x;
        break;
      }
    }
    for (int i = 0; i < m; i++) {
      int keta = p[i].first - 1;
      int kazu = p[i].second;
      if (number[keta] - 48 != kazu) break;
      if (i == (m - 1)) ret = x;
    }
    if (ret != -1) break;
  }
  cout << ret << endl;
}
