#include <bits/stdc++.h>
int main(void) {
  int N = 0;
  int M = 0;
  int ans = 0;
  int cal = 0;
  int s[5] = {0};
  int c[5] = {0};
  int rank[3] = {-1};
  scanf("%d %d", &N, &M);
  for (size_t i = 0; i < M; i++) {
    scanf("%d %d", &s[i], &c[i]);
  }
  for (size_t i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0) {
      printf("-1\n");
      return 0;
    }
    for (size_t j = i; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        printf("-1\n");
        return 0;
      }
    }
    rank[s[i] - 1] = c[i];
  }
  for (size_t i = 0; i < N; i++) {
    cal = 1;
    if (rank[i] != -1) {
      for (size_t j = i; j < N - 1; j++) {
        cal *= 10;
      }
      ans += rank[i] * cal;
    } else if (i == 0) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", ans);
  return 0;
}
