#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M, ans = 0;
  cin >> N >> M;
  vector<long long> s(M), c(M);
  for (long long x = 0; x < (long long)M; x++) cin >> s[x] >> c[x];
  vector<long long> keta(N);
  for (long long j = 0; j < (long long)M; j++) {
    if (keta[N - s[j]] == 0 || keta[N - s[j]] == c[j]) {
      keta[N - s[j]] = c[j];
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (N > 1 && keta[N - 1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  long long J = 1;
  for (long long i = 0; i < (long long)N; i++) {
    ans += J * keta[i];
    J *= 10;
  }
  cout << ans << endl;
  return 0;
}
