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