#include <bits/stdc++.h>
using namespace std;
int main() {
  char ans[] = "nnn";
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0, s, c; i < m; ++i) {
    scanf("%d%d", &s, &c);
    if (ans[s - 1] == n) {
      printf("-1\n");
      return 0;
    } else {
      ans[s - 1] = c + '0';
    }
  }
  if (ans[0] == '0' || ans[0] == 'n') {
    printf("-1\n");
  } else {
    for (int i = 0; i < 3; ++i) {
      if (ans[i] == 'n') {
        printf("0");
      } else {
        printf("%c", ans[i]);
      }
    }
    printf("\n");
  }
}
