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