#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, bool>> ans1(N, (make_pair(0, false)));
  bool ans2 = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      ans2 = false;
    } else if (ans1.at(s - 1).second && ans1.at(s - 1).first != c) {
      ans2 = false;
    } else {
      ans1.at(s - 1) = make_pair(c, true);
    }
  }
  if (N != 1 && ans1.at(0).first == 0) {
    ans1.at(0).first = 1;
  }
  if (ans2) {
    for (int i = 0; i < N; i++) {
      cout << ans1.at(i).first;
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
