#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y;
  int a, b, c;
  cin >> n >> m;
  a = -1;
  b = 0;
  c = 0;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (x == 1) a = y;
    if (x == 2) b = y;
    if (x == 3) c = y;
  }
  if (n == 1) {
    cout << a << endl;
    return 0;
  }
  if (n == 2) {
    if (a == -1 || a == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      cout << a << b << endl;
      return 0;
    }
  }
  int z, ans = -1, tmp;
  if (a == -1 || a == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 100; i < 1000; i++) {
    tmp = i;
    z = tmp % 10;
    tmp /= 10;
    y = tmp % 10;
    tmp /= 10;
    x = tmp % 10;
    if (x == a && y == b & z == c) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
