#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  int ans[4], zero, flg;
  cin >> n >> m;
  for (int i = 0; i < 4; i++) ans[i] = -1;
  flg = 1;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s - 1] != -1 && ans[s - 1] != c) {
      flg = 0;
      break;
    } else {
      ans[s - 1] = c;
    }
  }
  if (n != 1 && ans[0] == 0) flg = 0;
  if (!flg) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      cout << (ans[i] == -1 ? 0 : ans[i]);
    }
    cout << endl;
  }
  return 0;
}
