#include <bits/stdc++.h>
using namespace std;
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  for (int i = 0; i < 1000; i++) {
    bool isOk = true;
    for (int j = 0; j < M; j++) {
      if ((i % (int)pow(10, N - s[j] + 1)) / (int)pow(10, N - s[j]) != c[j]) {
        isOk = false;
      }
    }
    if (isOk && (i >= pow(10, N - 1))) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
