#include <bits/stdc++.h>
int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);
  int a[2][M], z[M];
  for (int i = 0; i < M; i++) {
    scanf("%d %d", &a[0][i], &a[1][i]);
    z[i] = 0;
    for (int j = 0; j < i; j++) {
      if (a[0][i] == a[0][j] && a[1][i] != a[1][j]) {
        printf("-1\n");
        return 0;
      }
    }
  }
  for (int i = 0; i < M; i++) z[a[0][i] - 1] = a[1][i];
  if (z[0] == 0)
    printf("-1\n");
  else {
    int y = 0;
    for (int i = 0; i < M; i++) y += z[i] * pow(10, M - (i + 1));
    printf("%d\n", y);
  }
  return 0;
}
