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