#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  vector<int> ans(N, -1);
  bool flag = true;
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
    if (ans.at(s.at(i) - 1) == -1 || ans.at(s.at(i) - 1) == c.at(i)) {
      if (N == 1) {
        ans.at(s.at(i) - 1) = c.at(i);
      } else if (i == 0) {
        ans.at(s.at(i) - 1) = c.at(i) == 0 ? -1 : c.at(i);
      } else {
        ans.at(s.at(i) - 1) = c.at(i);
      }
    } else {
      flag = false;
    }
  }
  if (ans.at(0) == 0) flag = false;
  if (flag) {
    for (int i = 0; i < N; i++) {
      cout << (ans.at(i) != -1 ? ans.at(i) : i == 0 ? N == 1 ? 0 : 1 : 0);
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
