#include <bits/stdc++.h>
const int INF = (int)1e9;
const long long MOD = (long long)1e9 + 7;
const long long LINF = (long long)4e18 + 20;
const long double PI = acos(-1.0);
const double EPS = 1e-9;
using namespace ::std;
void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  vector<int> num(N, -1);
  for (int i = 0; i < M; ++i) {
    cin >> A[i] >> B[i];
    if (A[i] > N) {
      cout << -1 << endl;
      return;
    }
    if (A[i] == 1 && B[i] == 0 && N > 1) {
      cout << -1 << endl;
      return;
    }
    if (num[A[i] - 1] == -1) {
      num[A[i] - 1] = B[i];
    } else if (num[A[i] - 1] != B[i]) {
      cout << -1 << endl;
      return;
    }
  }
  if (N == 1) {
    if (num[0] == -1) {
      num[0] = 0;
    }
  } else {
    for (int i = 0; i < N; ++i) {
      if (num[i] == -1) {
        num[i] = 0;
      }
    }
  }
  for (int i = 0; i < 3; ++i) {
    cout << num[i];
  }
  cout << endl;
}
signed main(void) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed;
  cout << setprecision(16);
  solve();
}
