#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < N; ++i) cin >> s[i] >> c[i], s[i]--;
  auto ok = [&](int n) -> bool {
    string S = to_string(n);
    if (S.size() != N) return false;
    for (int i = 0; i < M; ++i) {
      if (S[s[i]] != ('0' + c[i])) return false;
    }
    return true;
  };
  for (int i = 0; i < 1010; ++i) {
    if (ok(i)) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
