#include <bits/stdc++.h>
int main() {
  int dig[5], n, m, c, s;
  bool bl = true;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    dig[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &s, &c);
    if (dig[s] == -1 || dig[s] == c)
      dig[s] = c;
    else
      bl = false;
  }
  if (dig[1] == 0 && n != 1) bl = false;
  if (bl) {
    for (int i = 1; i <= n; i++) {
      if (dig[i] == -1)
        printf("0");
      else
        printf("%d", dig[i]);
    }
    printf("\n");
  } else
    printf("-1\n");
  return 0;
}
