#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0);
  int s, si;
  for (int i = 0; i < m; i++) {
    cin >> s;
    if (a[s - 1] != 0) {
      s = min(s, a[s - 1]);
    }
    cin >> a[s - 1];
  }
  if (a[0] == 0 || (a[0] == 0 && a[1] == 0))
    cout << -1 << endl;
  else
    cout << a[0] << a[1] << a[2] << endl;
}
