#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const ll INF = 1LL << 40;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll t1[6], t2[6];
int main() {
  ll n, m, ans = 1e9;
  cin >> n >> m;
  for (ll i = ll(0); i < ll(m); i++) cin >> t1[i] >> t2[i];
  ll m1 = powl(10, n), m2 = powl(10, n - 1);
  if (n == 1) m2 = 0;
  for (ll i = ll(m2); i < ll(m1); i++) {
    string t3 = to_string(i);
    bool t4 = true;
    for (ll i = ll(0); i < ll(m); i++) {
      if (t2[i] > n) t4 = false;
      char x = t3[t1[i] - 1];
      ll y = x - '0';
      if (y != t2[i]) t4 = false;
    }
    if (t4) {
      ans = i;
      break;
    }
  }
  if (ans == 1e9)
    cout << -1;
  else
    cout << ans;
}
