#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const int mINF = -1001001001;
int main() {
  int n, m;
  cin >> n >> m;
  int s;
  char c;
  char ans[n];
  int check[n];
  bool flg = true;
  for (int i = 0; i < (m); i++) {
    cin >> s >> c;
    if (check[s - 1] != 0 && ans[s - 1] != c) flg = false;
    check[s - 1]++;
    ans[s - 1] = c;
  }
  if (flg == true) {
    cout << ans << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
