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