#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int s[10] = {0};
  int c[10] = {0};
  for (int i = 1; i <= M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 1; i <= M; i++) {
    if ((N != 3) && (s[i] == 1)) {
      cout << -1 << endl;
      return 0;
    }
    if ((N != 3) && (N != 2) && (s[i] == 2)) {
      cout << -1 << endl;
      return 0;
    }
  }
  bool R[5] = {false};
  int D[5] = {0};
  for (int i = 1; i <= M; i++) {
    int r = s[i];
    int d = c[i];
    if (R[r] != true) {
      R[r] = true;
      D[r] = d;
      continue;
    }
    if (D[r] != d) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << D[1] * 100 + D[2] * 10 + D[3] << endl;
  return 0;
}
