#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  for (int i = 0; i < m; i++) cin >> p[i].first >> p[i].second;
  for (int i = 0; i < 1000; i++) {
    int k = 0, x = i;
    vector<int> d;
    while (x > 0) {
      k++;
      d.push_back(x % 10);
      x /= 10;
    }
    if (i == 0) d.push_back(0);
    reverse(d.begin(), d.end());
    if (k != n) continue;
    bool flag = true;
    for (int j = 0; j < k; j++) {
      for (int l = 0; l < m; l++) {
        if (d[p[l].first - 1] != p[l].second) flag = false;
      }
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
