#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int A;
  cin >> A;
  int B;
  cin >> B;
  vector<vector<ll>> vec(B, vector<ll>(2));
  for (ll i = 0; i < B; i++) {
    cin >> vec.at(i).at(0) >> vec.at(i).at(1);
  }
  ll c = -1;
  ll d = 1;
  if (A > 2) {
    for (int i = 1; i < A; i++) {
      d = d * 10;
    }
  }
  for (int i = d; i < 10 * d; i++) {
    string b = to_string(i);
    for (ll j = 0; j < B; j++) {
      if (b.at(vec.at(j).at(0) - 1) != vec.at(j).at(1)) {
        break;
      }
      if (j == B - 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << c << endl;
  return 0;
}
