#include <bits/stdc++.h>
using namespace std;
long long fast_pow(long long x, long long y, long long p);
void solve() {
  long long n, m;
  cin >> n >> m;
  pair<long long, char> a[m];
  for (long long i = 0; i < m; i++) {
    cin >> a[i].first >> a[i].second;
  }
  for (long long i = 1; i <= 999; i++) {
    string s = to_string(i);
    if (s.length() == n) {
      bool b = true;
      for (long long j = 0; j < m; j++) {
        if (s[a[j].first - 1] != a[j].second) b = false;
      }
      if (b) {
        cout << i << "\n";
        return;
      }
    }
  }
  cout << -1 << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
long long fast_pow(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
