#include <bits/stdc++.h>
int main(void) {
  int n;
  int m;
  int s[5];
  int c[5];
  int d[3];
  scanf("%d %d", &n, &m);
  for (int i = 0; i < 3; i++) {
    d[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &s[i], &c[i]);
    if (d[s[i] - 1] != -1 && c[i] != d[s[i] - 1]) {
      printf("-1");
      return 0;
    }
    d[s[i] - 1] = c[i];
  }
  if (d[0] == 0) {
    if (n != 1) {
      printf("-1");
      return 0;
    } else {
      printf("0");
      return 0;
    }
  }
  if (d[0] == -1) d[0] = 1;
  if (d[1] == -1) d[1] = 0;
  if (d[2] == -1) d[2] = 0;
  if (n == 3)
    printf("%d", d[0] * 100 + d[1] * 10 + d[2]);
  else if (n == 2)
    printf("%d", d[0] * 10 + d[1]);
  else if (n == 1)
    printf("%d", d[0]);
}
