#include <bits/stdc++.h>
int main(void) {
  int n;
  int m;
  int s[6];
  int c[6];
  int a;
  int t;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &s[i], &c[i]);
  }
  int k[n + 2];
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    a = 0;
    t = i;
    for (int g = n; g > 0; g--) {
      k[g] = i % 10;
      i /= 10;
    }
    i = t;
    for (int j = 0; j < m; j++) {
      if (k[s[i]] == c[i]) {
        a++;
      } else {
        break;
      }
    }
    if (a == m) {
      printf("%d", i);
      break;
    }
  }
  if (a != m) {
    printf("-1");
  }
  return 0;
}
