#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> checked(N);
  string r;
  for (long long i = 0; i < (long long)(N); i++) r += " ";
  for (long long i = 0; i < (long long)(M); i++) {
    int s;
    char c;
    cin >> s >> c;
    if (r.at(s - 1) != ' ' && r.at(s - 1) != c) {
      cout << -1 << endl;
      return 0;
    }
    r.at(s - 1) = c;
    checked.at(s - 1) = true;
  }
  if (1 < N && r.at(0) == ' ') {
    cout << -1 << endl;
    return 0;
  }
  replace(r.begin(), r.end(), ' ', '0');
  cout << r << endl;
}
