#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int main(void) {
  int N, M;
  cin >> N >> M;
  int A[N];
  for (int i = 0; i < N; i++) A[i] = -1;
  bool ok = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (A[s] != -1 && c != A[s])
      ok = false;
    else
      A[s] = c;
    if (A[0] == 0) ok = false;
  }
  if (A[0] == -1) A[0] = 1;
  if (A[1] == -1) A[1] = 0;
  if (A[2] == -1) A[2] = 0;
  if (ok)
    cout << A[0] << A[1] << A[2] << endl;
  else
    cout << -1 << endl;
  return 0;
}
