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