#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] = 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (ans[s] != 0 && ans[s] != c) {
      printf("%d", -1);
      return 0;
    } else {
      ans[s] = c;
    }
  }
  if (ans[1] == 0) {
    printf("%d", -1);
  } else {
    for (int i = 0; i < n; i++) {
      call += ans[n - i] * deg;
      deg *= 10;
    }
    printf("%d", call);
  }
  return 0;
}
