#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll power10(ll d) {
  ll x = 1;
  for (ll(i) = (0), i_len = (d); (i) < (i_len); ++(i)) x *= 10;
  return x;
}
int main() {
  ll N, M;
  cin >> N >> M;
  ll s[M], c[M];
  for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
    cin >> s[i] >> c[i];
    --s[i];
  }
  ll num = -1;
  ll L = power10(N - 1);
  ll U = power10(N);
  bool f = true;
  if (N == 1) {
    for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
      if (s[i] == 0 && c[i] != 0) {
        f = false;
        break;
      }
    }
    if (f) num = 0;
  }
  f = true;
  vector<ll> T(M, -1);
  for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
    if (T[s[i]] = -1) T[s[i]] = c[i];
    if (T[s[i]] != -1 && T[s[i]] != c[i]) {
      f = false;
      break;
    }
  }
  for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
    if (T[i] == -1) T[i] = 0;
  }
  ll temp;
  if (num != 0 && f) {
    for (ll(i) = (L), i_len = (U); (i) < (i_len); ++(i)) {
      temp = 0;
      for (ll(j) = (0), j_len = (M); (j) < (j_len); ++(j)) {
        temp += T[j] * power10(N - j - 1);
      }
      if (i == temp) {
        num = i;
        break;
      }
    }
  }
  cout << (num) << endl;
  return 0;
}
