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