#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int inf = 1e9;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, -1, 0, 1};
template <class t, class u>
void chmax(t& a, u b) {
  if (a < b) a = b;
}
template <class t, class u>
void chmin(t& a, u b) {
  if (b < a) a = b;
}
long long fac(ll a) {
  long long ans = 1;
  while (a > 1) {
    ans *= a;
    ans %= 1000000007;
    a--;
  }
  return ans;
}
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
struct UF {
  vl par;
  UF(ll N) : par(N) {
    for (ll i = 0; i < N; i++) par[i] = i;
  }
  ll root(ll x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  bool same(ll x, ll y) { return root(x) == root(y); }
  void unite(ll x, ll y) {
    x = root(x), y = root(y);
    if (x == y) return;
    par[x] = y;
    return;
  }
};
int main() {
  ll N;
  ll M;
  cin >> N >> M;
  vl s(M);
  vl c(M);
  for (ll i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  ll d = 0;
  for (ll i = (1); i < (1000); i++) {
    bool ans = true;
    string a = to_string(i);
    for (ll j = 0; j < M; j++) {
      if ((s.at(j) - 1 < 0) || (s.at(j) - 1 > a.size() - 1)) {
        ans = false;
        continue;
      } else if ((a.at(s.at(j) - 1) == c.at(j) + '0')) {
        continue;
      } else {
        ans = false;
      }
    }
    if (ans) {
      cout << i << endl;
      d = 1;
      return 0;
    } else {
      continue;
    }
  }
  if (d == 0) {
    cout << -1 << endl;
    return 0;
  }
}
