#include <bits/stdc++.h>
using namespace std;
int pow(int n, int k) {
  int res = 1;
  for (int i = 0; i < k; i++) {
    res *= n;
  }
  return res;
}
int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  int s[5];
  int c[5];
  for (int i = 0; i < M; i++) scanf("%d %d", &s[i], &c[i]);
  int base = pow(10, N - 1);
  if (N == 1) base = 0;
  int check[4];
  for (int i = 0; i < 4; i++) check[i] = -1;
  for (int i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0 && N != 1) {
      printf("%d\n", -1);
      return 0;
    }
    if (check[s[i]] == -1) {
      if (s[i] == 1) {
        base += pow(10, N - s[i]) * (c[i] - 1);
      } else {
        base += pow(10, N - s[i]) * c[i];
      }
      check[s[i]] = c[i];
    } else {
      if (check[s[i]] != c[i]) {
        printf("%d\n", -1);
        return 0;
      }
    }
  }
  printf("%d\n", base);
  return 0;
}
