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