#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int first = 100, second = 100, third = 100;
  vector<int> flag(3, 0);
  for (int i = 1; i <= M; i++) {
    int s;
    cin >> s;
    if (s == 1) {
      int c;
      cin >> c;
      if (first != c && first != 100) {
        cout << -1 << endl;
        return 0;
      } else {
        first = c;
        flag[0] = 1;
      }
    }
    if (s == 2) {
      int c;
      cin >> c;
      if (second != c && second != 100) {
        cout << -1 << endl;
        return 0;
      } else {
        second = c;
        flag[1] = 1;
      }
    }
    if (s == 3) {
      int c;
      cin >> c;
      if (third != c && third != 100) {
        cout << -1 << endl;
        return 0;
      } else {
        third = c;
        flag[2] = 1;
      }
    }
  }
  if (first == 0 && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  if (N < 3) {
    for (int i = N + 1; i <= 3; i++) {
      if (flag[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (first == 100) {
    first = 1;
    if (second == 100) second = 0;
    if (third == 100) third = 0;
  } else {
    if (second == 100) second = 0;
    if (third == 100) third = 0;
  }
  cout << first * 100 + second * 10 + third << endl;
  return 0;
}
