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