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