#include <bits/stdc++.h>
using namespace std;
int A[3];
int N, M;
bool a = true;
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    A[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (A[s - 1] == -1 || A[s - 1] == c) {
      A[s - 1] = c;
    } else {
      a = false;
    }
  }
  if (a) {
    for (int i = 0; i < N; i++) {
      if (A[i] == -1) {
        cout << 0;
      } else {
        cout << A[i];
      }
    }
  } else {
    cout << -1 << endl;
  }
}
