#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m + 5];
  char c[m + 5];
  string a = "";
  for (int i = 0; i < n; i++) a += '0';
  for (int i = 0; i < m; i++) {
    int x;
    char y;
    cin >> x >> y;
    x--;
    s[i] = x;
    c[i] = y;
    if (a[x] == '0')
      a[x] = y;
    else
      a[x] = min(a[x], y);
  }
  char mn = 'a';
  for (int i = 0; i < m; i++) {
    if (s[i] == 0 && c[i] != '0') mn = min(mn, c[i]);
  }
  a[0] = mn;
  if (n == 1 && mn == 'a') {
    cout << 0 << endl;
    return 0;
  }
  if (mn == 'a')
    cout << -1 << endl;
  else
    cout << a << endl;
  return 0;
}
