#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool ok = true;
  string ans(n, '0');
  for (int i = 0; i < m; i++) {
    int s;
    cin >> s;
    char c;
    cin >> c;
    if (ans[s - 1] == '0')
      ans[s - 1] = c;
    else if (ans[s - 1] != c)
      ok = false;
  }
  if (ans[0] == '0') ok = false;
  cout << (ok ? ans : "-1");
}
