#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) {
  std::vector<long long> num(N);
  long long ans;
  for (int n = 0; n < N; n++) {
    num[n] = 10;
  }
  for (int m = 0; m < M; m++) {
    if (num[N - s[m]] != 10 && num[N - s[m]] != c[m]) {
      ans = -1;
      cout << ans << endl;
      return;
    }
    num[N - s[m]] = c[m];
  }
  for (int n = 0; n < N; n++) {
  }
  if (num[N - 1] == 0) {
    ans = -1;
    cout << ans << endl;
    return;
  }
  ans = 0;
  for (int n = 0; n < N; n++) {
    if (num[n] == 10) {
      if (n == N - 1 && N != 1) {
        num[n] = 1;
      } else {
        num[n] = 0;
      }
    }
    ans += num[n] * std::pow(10, n);
  }
  cout << ans << 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;
}
