#include <bits/stdc++.h>
using namespace std;
long long llPow(long long a, long long n) {
  if (n == 0) return 1;
  if (n == 1) return a;
  return a * llPow(a, n - 1);
}
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M), c(M);
  for (int(i) = 0; (i) < (M); ++(i)) cin >> s[i] >> c[i];
  long long ans = -1;
  long long start = llPow(10, N - 1);
  long long end = llPow(10, N) - 1;
  for (long long i = start; i <= end; ++i) {
    bool flag = true;
    vector<long long> digit(N);
    long long num = i;
    long long count = 0;
    while (num > 0) {
      digit[count] = num % 10;
      num /= 10;
      count++;
    }
    for (int(i) = 0; (i) < (M); ++(i)) {
      if (N - s[i] < 0) break;
      if (digit[N - s[i]] != c[i]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
