#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> limitation(N + 1, 0);
  vector<bool> visit(N + 1, false);
  int s, c;
  for (int i = int(0); i < int(M); ++i) {
    cin >> s >> c;
    if (visit.at(s)) {
      if (limitation.at(s) == c) {
        continue;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
    limitation.at(s) = c;
    visit.at(s) = true;
  }
  for (int i = int(0); i < int(1001); ++i) {
    stringstream ss;
    ss << i;
    string t_s = ss.str();
    if ((int)t_s.length() == N) {
      bool ok = true;
      for (int j = 0; j < N; ++j) {
        if (t_s.at(j) == limitation.at(j + 1) + '0') {
          continue;
        }
        ok = false;
        break;
      }
      if (ok) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
