#include <bits/stdc++.h>
int main() {
  int n, m;
  if (scanf("%d%d*c", &n, &m) == EOF) {
    return 0;
  }
  int s, c;
  int num[n];
  for (int i = 0; i < n; i++) {
    num[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    if (scanf("%d%d*c", &s, &c) == EOF) {
      return 0;
    }
    if (n == 1 && s == 1 && c == 0) {
      num[s - 1] = -1;
    } else if (n != 1 && s == 1 && c == 0) {
      printf("-1\n");
      return 0;
    } else if (num[s - 1] == 0 || num[s - 1] == c) {
      num[s - 1] = c;
    } else {
      printf("-1\n");
      return 0;
    }
  }
  int ans = 0;
  if (num[0] == 0) {
    num[0] = 1;
  }
  if (num[0] == -1) {
    num[0] = 0;
  }
  for (int i = 0; i < n; i++) {
    ans += pow(10, n - 1 - i) * num[i];
  }
  printf("%d\n", ans);
  return 0;
}
