#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, t;
  int a = 999;
  int b = 999;
  int c = 999;
  bool resu = true;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> t;
    if (s == 1 && t != 0) {
      if (a == 999 || a == t) {
        a = t;
      } else {
        resu = false;
      }
    } else if (s == 2) {
      if (b == 999 || b == t) {
        b = t;
      } else {
        resu = false;
      }
    } else if (s == 3) {
      if (c == 999 || c == t) {
        c = t;
      } else {
        resu = false;
      }
    } else {
      resu = false;
    }
  }
  if (resu) {
    if (a == 999) {
      a = 0;
    }
    if (b == 999) {
      b = 0;
    }
    if (c == 999) {
      c = 0;
    }
    cout << a * 100 + b * 10 + c;
  } else {
    cout << "-1";
  }
}
