#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); ++i) cin >> s.at(i) >> c.at(i);
  for (int x = 0; x < (1000); ++x) {
    int keta = 1;
    vector<int> d;
    while (x > 0) {
      keta++;
      d.push_back(x % 10);
      x /= 10;
    }
    reverse(d.begin(), d.end());
    if (keta != n) continue;
    bool ok = true;
    for (int i = 0; i < (m); ++i) {
      if (d.at(s.at(i)) != c.at(i)) ok = false;
    }
    if (ok) cout << x << endl;
  }
  cout << -1 << endl;
}
