#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> digits(n, 0);
  unordered_map<int, int> inputs;
  bool canCreate = true;
  for (int i = 0; i < (int)(m); ++i) {
    int s, c;
    cin >> s >> c;
    const auto itr = inputs.find(s);
    if (s == 1 && c == 0) {
      canCreate = false;
    }
    if (itr != inputs.end() && itr->second != c) {
      canCreate = false;
    }
    inputs[s] = c;
    digits[s - 1] = c;
  }
  if (!canCreate) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (int)(n); ++i) {
    cout << digits[i];
  }
  cout << endl;
  return 0;
}
