#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s, c;
  int p = 0, q = 0, r = 0, ans = 0;
  int pcounter = 0, qcounter = 0, rcounter = 0;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    if (s == 1) {
      if (pcounter != 0 && c != p) {
        ans = 1;
        break;
      } else {
        ++pcounter;
        p = c;
      }
    } else if (s == 2) {
      if (qcounter != 0 && c != q) {
        ans = 1;
        break;
      } else {
        ++qcounter;
        q = c;
      }
    } else if (s == 3) {
      if (rcounter != 0 && c != r) {
        ans = 1;
        break;
      } else {
        ++rcounter;
        r = c;
      }
    }
  }
  if (ans == 1) {
    cout << "-1"
         << "\n";
  } else if (ans == 0 && n == 3 && p == 0) {
    cout << "-1"
         << "\n";
  } else if (ans == 0 && n == 2 && p == 0 && q == 0) {
    cout << "-1"
         << "\n";
  } else {
    cout << r + q * 10 + p * 100 << "\n";
  }
  return 0;
}
