#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e18;
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<long long> a(m);
  vector<char> c(m);
  for (long long i = 0; i < m; i++) cin >> a[i] >> c[i];
  for (long long i = 1; i < 1000; i++) {
    string s = to_string(i);
    if (s.size() != n) continue;
    bool f = true;
    for (long long j = 0; j < m; j++) {
      if (s[a[j] - 1] != c[j]) {
        f = false;
        break;
      }
    }
    if (f) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
