#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c;
  int* ans;
  int call = 0;
  int deg = 1;
  cin >> n >> m;
  ans = new int[n + 1];
  for (int i = 0; i <= n; i++) {
    ans[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (ans[s] == -1 || ans[s] == c) {
      ans[s] = c;
    } else {
      printf("%d", -1);
      return 0;
    }
    if (s == 1 && c == 0) {
      printf("%d", -1);
      return 0;
    }
  }
  if (ans[1] == -1) {
    ans[1] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (ans[n - i] == -1) {
      ans[n - i] = 0;
    }
    call += ans[n - i] * deg;
    deg *= 10;
  }
  printf("%d", call);
  return 0;
}
