#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > P(M);
  for (int i = 0; i < (N); i++) cin >> P[i].first >> P[i].second;
  for (int i = 0; i < (1000); i++) {
    string S = to_string(i);
    int keta = S.length();
    if (keta != N) continue;
    bool ok = true;
    for (int i = 0; i < (M); i++) {
      if (S[P[i].first - 1] != P[i].second + '0') ok = false;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
