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