#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  bool check = true;
  cin >> n >> m;
  int a = 1, b = 0, c = 0;
  bool ach = true, bch = true, cch = true;
  if (n == 2) a = 0, b = 1, c = 0;
  if (n == 1) a = 0, b = 0, c = 0;
  for (int i = 0; i < m; i++) {
    int cs, bs;
    cin >> cs >> bs;
    int x = 0;
    if (cs > n) check = false;
    if (cs == 1 && bs == 0) check = false;
    if (n == 3 && cs == 1 && a == bs) continue;
    if (n == 3 && cs == 2 && b == bs) continue;
    if (n == 3 && cs == 3 && c == bs) continue;
    if (n == 2 && cs == 1 && b == bs) continue;
    if (n == 2 && cs == 2 && c == bs) continue;
    if (n == 1 && cs == 1 && c == bs) continue;
    if (n == 3 && cs == 1 && ach == true) {
      a = bs;
      ach = false;
      x++;
    }
    if (n == 3 && cs == 2 && bch == true) {
      b = bs;
      bch = false;
      x++;
    }
    if (n == 3 && cs == 3 && cch == true) {
      c = bs;
      cch = false;
      x++;
    }
    if (n == 2 && cs == 1 && bch == true) {
      b = bs;
      bch = false;
      x++;
    }
    if (n == 2 && cs == 2 && cch == true) {
      c = bs;
      cch = false;
      x++;
    }
    if (n == 1 && cs == 1 && cch == true) {
      c = bs;
      cch = false;
      x++;
    }
    if (x == 0) check = false;
  }
  if (check) {
    cout << 100 * a + 10 * b + c << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
