#include <bits/stdc++.h>
using namespace std;
long long int N, M, A, B, C;
long long int arr[15];
vector<long long int> V;
long long int mark[15];
long long int ans[15], arr1[15];
int main() {
  scanf("%lld %lld", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%lld %lld", &arr[i], &arr1[i]);
    if (ans[arr[i]] != 0 && ans[arr[i]] != arr1[i]) {
      printf("-1\n");
      exit(0);
    }
    ans[arr[i]] = arr1[i];
    mark[arr[i]] = 1;
  }
  for (int i = 1; i <= N; i++) {
    if (i == 1 && !mark[i]) {
      ans[i] = 1;
    } else {
      if (!mark) {
        ans[i] = 0;
      }
    }
  }
  if (N == 1 && ans[1] == 0) {
    printf("0\n");
    exit(0);
  }
  for (int i = 1; i <= 999; i++) {
    long long int X = i;
    int flag = 1;
    long long int cnt = 0;
    while (X) {
      long long int tmp = X % 10;
      if (tmp != ans[N - cnt]) {
        flag = 0;
        break;
      }
      X /= 10;
      cnt++;
    }
    if (cnt != N) {
      continue;
    }
    if (flag) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
