#include <bits/stdc++.h>
int main(void) {
  int N = 0;
  int M = 0;
  int ans = 0;
  int cal = 1;
  bool flag = true;
  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]);
  }
  if (M == 0 && N != 1) {
    flag = false;
  }
  for (size_t i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0 && N >= 2) {
      flag = false;
    }
    for (size_t j = i; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        flag = false;
      }
    }
    rank[s[i] - 1] = c[i];
  }
  if (flag == false) {
    printf("-1\n");
  } else {
    if (rank[0] == -1) {
      rank[0] = 1;
    }
    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;
  }
}
