#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll mod(ll A, ll M) { return (A % M + M) % M; }
const ll INF = 1LL << 60;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll divceil(ll A, ll B) { return (A + (B - 1)) / B; }
ll myctoi(char C) { return C - '0'; }
char myitoc(ll N) { return '0' + N; }
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> S(M), C(M);
  for (ll i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
    S.at(i)--;
  }
  for (ll n = 0; n < 1000; n++) {
    string x = to_string(n);
    if (x.size() != N) continue;
    bool ok = true;
    for (ll i = 0; i < N; i++) {
      if (x.at(S.at(i)) - '0' != C.at(i)) {
        ok = false;
        break;
      }
    }
    if (ok) do {
        cout << (n) << '\n';
        exit(0);
      } while (false);
  }
  cout << -1 << endl;
}
