#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
using Pa = pair<T, U>;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vec<int> S(M), C(M);
  for (int i = 0; i < M; i++) cin >> S[i] >> C[i];
  vec<int> beki(N + 2, 1);
  for (int i = 1; i <= N + 1; i++) beki[i] = beki[i - 1] * 10;
  auto keta = [&](int n, int i) {
    string s = to_string(n);
    return s[i - 1] - '0';
  };
  for (int i = beki[N - 1] - (N == 0); i < beki[N]; i++) {
    bool ok = true;
    for (int j = 0; j < M; j++) ok &= keta(i, S[j]) == C[j];
    if (ok) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
}
