#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  for (long long i = 0; i < (m); ++i) {
    cin >> a[i].first >> a[i].second;
  }
  bool jud = true;
  for (long long i = 0; i < (1000); ++i) {
    string t = to_string(i);
    if (t.size() != n) continue;
    for (long long i = 0; i < (m); ++i) {
      if (t[a[i].first - 1] != a[i].second) jud = false;
    }
    if (jud) {
      cout << i << endl;
      return 0;
    }
  }
  cout << (-1) << endl;
}
