#include <bits/stdc++.h>
using namespace std;
int main() {
  int n[4] = {-1, -1, -1, -1};
  int N, M;
  cin >> N >> M;
  while (M--) {
    int s, c;
    cin >> s >> c;
    if (n[s] != -1 && n[s] != c) {
      printf("-1");
      return 0;
    }
    n[s] = c;
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans *= 10;
    if (n[i] == -1) {
      if (i == 1) continue;
    } else {
      ans += n[i];
    }
  }
  if (ans == 0 || (N == 3 && ans < 100) || (N == 2 && ans < 10)) {
    printf("-1");
    return 0;
  }
  printf("%d", ans);
  return 0;
}
