#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll t1, t2, t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x, ll *y) {
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
ll calc(ll k) {
  if (k == 0) {
    return 0;
  } else {
    return 1 + calc(k / 10);
  }
}
int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> pa(m);
  for (int i = 0; i < m; i++) {
    cin >> t1 >> t2;
    t1 = (ll)pow(10, n - t1);
    pa[i] = make_pair(t1, t2);
  }
  ll maxi = (ll)pow(10, n);
  ll ans = -1;
  ll st = maxi / 10;
  for (int i = 0; i < 10000; i++) {
    bool can = true;
    for (int j = 0; j < m; j++) {
      if (i / pa[j].first % (pa[j].first * 10) != pa[j].second) {
        can = false;
        break;
      }
    }
    ll keta = calc(i / 10);
    if (can && keta + 1 == n) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
