#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[3] = {-1, -1, -1};
  int n, m;
  cin >> n >> m;
  bool it = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (arr[s - 1] == -1) {
      arr[s - 1] = c;
    }
    if (arr[s - 1] != -1) {
      it = false;
    }
  }
  if (!it)
    cout << -1 << endl;
  else {
    for (int i = 0; i < 3; i++) {
      if (arr[i] == -1) {
        cout << 0;
      } else {
        cout << arr[i];
      }
    }
  }
  return 0;
}
