#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int solve() {
  ll N, M;
  cin >> N >> M;
  vector<ll> S(M), C(M);
  for (int i = 0; i < M; i++) {
    cin >> S[i] >> C[i];
  }
  ll st = 1;
  for (int i = 1; i < N; i++) {
    st *= 10;
  }
  for (int i = st; i < st * 10; i++) {
    bool ng = false;
    string s = to_string(i);
    for (int j = 0; j < M; j++) {
      if ((int)(s[S[j] - 1] - '0') != C[j]) {
        ng = true;
        break;
      }
    }
    if (!ng) {
      return i;
    }
  }
  return -1;
}
int main() {
  auto ans = solve();
  cout << ans << "\n";
  return 0;
}
