#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (num[s - 1] == -1) {
      num[s - 1] = c;
    } else if (num[s - 1] == c) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[0] == -1) {
    num[0] = 1;
  } else if ((n != 1) && (num[0] == 0)) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    if (num[i] == -1) {
      num[i] = 0;
    }
  }
  int ret = 0;
  for (int i = 0; i < n; i++) {
    ret = ret * 10 + num[i];
  }
  cout << ret << endl;
  return 0;
}
