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