#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, i, j, p, q;
  int a[4] = {0};
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> p >> q;
    if (a[p] < q && a[p] != 0)
      continue;
    else
      a[p] = q;
  }
  if (a[1] == 0) {
    if (m == 0)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  } else
    for (i = 1; i <= 3; i++) {
      cout << a[i];
    }
  cout << endl;
  return 0;
}
