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