#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, x, y, hu, te, on, none;
  hu = 100;
  te = 100;
  on = 100;
  none = 0;
  cin >> n >> a;
  for (int i = 0; i < a; i++) {
    cin >> x >> y;
    if (x == 1) {
      if (hu != y && hu != 100) {
        none = 1;
        break;
      }
      hu = y;
    }
    if (x == 2) {
      if (te != y && te != 100) {
        none = 1;
        break;
      }
      te = y;
      ;
    }
    if (x == 3) {
      if (on != y && on != 100) {
        none = 1;
        break;
      }
      on = y;
    }
  }
  if (n == 3) {
    if (hu == 100) hu = 1;
    if (hu == 0) {
      none = 1;
    }
    if (te == 100) te = 0;
    if (on == 100) on = 0;
  }
  if (n == 2) {
    if (te == 100) te = 1;
    if (te == 0) {
      none = 1;
    }
    if (on == 100) on = 0;
  }
  if (n == 1) {
    if (on == 100) on = 0;
  }
  if (none == 1)
    cout << -1 << endl;
  else if (n == 3)
    cout << hu << te << on << endl;
  else if (n == 2)
    cout << te << on << endl;
  else if (n == 1)
    cout << on << endl;
}
