#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int num[4] = {-1, -1, -1, -1};
  bool ans = true;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (num[s] == -1) {
      num[s] = c;
    } else if (num[s] != c) {
      ans = false;
    }
  }
  if ((N != 1) && (num[1] == 0)) {
    ans = false;
  }
  for (int i = 1; i < N + 1; i++) {
    if (num[i] == -1) {
      num[i] = 0;
    }
  }
  int ansnum = 0;
  if (!ans) {
    ansnum = -1;
  } else {
    for (int i = 1; i < N + 1; i++) {
      ansnum = ansnum * 10 + num[i];
    }
  }
  cout << ansnum << endl;
  return 0;
}
