#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, char>> vec(m);
  for (long long i = 0; i < (long long)(m); i++)
    cin >> vec[i].first >> vec[i].second;
  for (long long i = (pow(10, n - 1)); i < (long long)(pow(10, n)); i++) {
    bool yes = true;
    for (long long j = 0; j < (long long)(m); j++) {
      long long s = vec[j].first;
      char c = vec[j].second;
      string t = to_string(i);
      if (s < 1 || s > n) {
        yes = false;
        break;
      }
      if (t[s - 1] != c) {
        yes = false;
        break;
      }
    }
    if (yes) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
