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