#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int A[10];
  std::memset(A, -1, sizeof(A));
  int s, c;
  int ans = 0;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (A[s] != -1 && A[s] != c) {
      ans = -1;
    } else {
      A[s] = c;
    }
  }
  if (N != 1 && A[1] == 0) {
    ans = -1;
  }
  if (A[1] == -1) {
    ans = -1;
  }
  if (ans != -1) {
    for (int i = 1; i <= N; i++) {
      if (A[i] == -1) {
        A[i] = 0;
      }
      cout << A[i];
    }
    cout << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
