#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  vector<int> A(3), s(M), c(M), B(3);
  for (int i = 0; i < 3; i++) {
    A[i] = 0;
    B[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < M; i++) {
    if (B[s[i] - 1] == 0)
      A[s[i] - 1] = c[i], B[s[i] - 1] = 1;
    else if (A[s[i] - 1] != c[i])
      ans = -1;
  }
  if (N == 1) {
    if (ans != -1) ans = A[0];
  } else if (N == 2) {
    if (A[0] == 0) {
      if (B[0] == 1) ans = -1;
    }
    if (ans != -1) ans = A[0] * 10 + A[1];
  } else if (N == 3) {
    if (A[0] == 0) {
      if (B[0] == 1) ans = -1;
    }
    if (ans != -1) ans = A[0] * 100 + A[1] * 10 + A[2];
  }
  cout << ans << endl;
}
