#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, n, m, p, q, r;
  cin >> n >> m;
  a = 10;
  b = 10;
  c = 10;
  r = 0;
  for (int i = 0; i < m; i++) {
    cin >> p >> q;
    if (p == 1) {
      if (a <= 9 && a != q) {
        cout << -1 << endl;
        r++;
        break;
      } else {
        a = q;
      }
    } else if (p == 2) {
      if (b <= 9 && b != q) {
        cout << -1 << endl;
        r++;
        break;
      } else {
        b = q;
      }
    } else if (p == 3) {
      if (c <= 9 && c != q) {
        cout << -1 << endl;
        r++;
        break;
      } else {
        c = q;
      }
    }
  }
  if (n == 1 && r == 0) {
    cout << a % 10 << endl;
  } else if (n == 2 && r == 0) {
    if (a == 0) {
      cout << -1 << endl;
    } else {
      cout << (a % 9) * 10 + (b % 10) << endl;
    }
  } else if (n == 3 && r == 0) {
    if (a == 0) {
      cout << -1 << endl;
    } else {
      cout << (a % 9) * 100 + (b % 10) * 10 + (c % 10) << endl;
    }
  }
}
