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