#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> Z(M, {0, 0});
  for (ll i = 0; i < M; ++i) {
    ll s, c;
    cin >> s >> c;
    Z[i] = {N - s, c};
  }
  ll end = 1;
  ll low = 1;
  for (ll i = 0; i < N; ++i) end *= 10;
  low = end / 10;
  low = max(1LL, low);
  for (ll i = low; i < end; i++) {
    ll a, b, c;
    a = i / 100;
    b = (i / 10) % 10;
    c = i % 10;
    for (ll j = 0; j < M; ++j) {
      ll z1 = Z[j].first, z2 = Z[j].second;
      if (z1 == 0 && c != z2) break;
      if (z1 == 1 && b != z2) break;
      if (z1 == 2 && a != z2) break;
      if (j == M - 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}
