#include <bits/stdc++.h>
int main() {
  int n, m;
  int s[5];
  int c[5];
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &s[i], &c[i]);
  }
  if (n == 1) {
    int tmp = 0;
    int flag = 0;
    int a[4];
    for (int j = 0; j < 4; j++) {
      a[j] = 0;
    }
    for (int j = 0; j < m; j++) {
      if (c[j] != a[s[j]]) flag = 1;
    }
    if (flag == 0) {
      printf("0");
      return 0;
    }
  }
  for (int i = 0; i < pow(10, n); i++) {
    int flag = 0;
    int a[3];
    int nx = i / 10;
    int keta = 1;
    a[0] = i % 10;
    int j = 0;
    while (nx > 0) {
      keta++;
      j++;
      a[j] = nx % 10;
      nx /= 10;
    }
    if (keta != n) continue;
    for (int j = 0; j < m; j++) {
      if (c[j] != a[3 - s[j]]) flag = 1;
    }
    if (flag == 0) {
      printf("%d", i);
      return 0;
    }
  }
  printf("-1");
  return 0;
}
