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