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