#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> vec(n);
  int s;
  string c;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    if (s == 1 && c == "0") {
      cout << -1 << endl;
      return 0;
    }
    if (vec.at(s - 1) == "") {
      vec.at(s - 1) = c;
    } else if (vec.at(s - 1) != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  string ans = "";
  if (vec.at(0) == "") {
    vec.at(0) = "1";
  }
  for (int i = 0; i < (int)(n); i++) {
    if (vec.at(i) == "") {
      ans += "0";
    } else {
      ans += vec.at(i);
    }
  }
  cout << ans << endl;
}
