#include <bits/stdc++.h>
int main(void) {
  int N, M;
  int ans[3] = {0, 0, 0};
  bool ansbool[3] = {true, true, true};
  int s[3];
  int c[3];
  int max = 9;
  scanf("%d %d", &N, &M);
  for (int k = 0; k < M; k++) {
    scanf("%d %d", &s[k], &c[k]);
    s[k]--;
    if (ansbool[s[k]]) {
      ansbool[s[k]] = false;
      ans[s[k]] = c[k];
    } else {
      if (ans[s[k] != c[k]]) {
        printf("-1");
        return 0;
      }
    }
  }
  for (int m = 0; m < 2; m++) {
    if ((ansbool[m] == false) && (ans[m] == 0)) {
      printf("-1");
      return 0;
    }
  }
  if (ans[0] == 0) {
    if (ans[1] == 0) {
      printf("%d", ans[2]);
    } else {
      printf("%d%d", ans[1], ans[2]);
    }
  } else {
    printf("%d%d%d", ans[0], ans[1], ans[2]);
  }
}
