#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> c(M);
  vector<int> s(M);
  vector<int> ans(N, -1);
  int af = 0;
  for (int i = (int)0; i < (int)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);
    } else if (ans.at(s.at(i) - 1) != c.at(i)) {
      af = 1;
    }
  }
  if (ans.at(0) == 0) af = 1;
  if (af == 1) {
    cout << "-1" << endl;
  } else {
    for (int i = (int)0; i < (int)N; i++) {
      if (ans.at(i) == -1) ans.at(i) = 0;
    }
    if (ans.at(0) == 0) ans.at(0) = 1;
    for (int i = (int)0; i < (int)N; i++) {
      cout << ans.at(i);
    }
    cout << endl;
  }
}
