#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 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]);
    ans[arr[i]] = arr1[i];
  }
  if (N == 1 && arr[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[M - cnt]) {
        flag = 0;
        break;
      }
      X /= 10;
      cnt++;
    }
    if (cnt != N) {
      continue;
    }
    if (flag) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
