#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
  int n, m;
  cin >> n >> m;
  string ans = "";
  for (int i = (0); i < (n); ++i) ans += '0';
  for (int i = (0); i < (m); ++i) {
    int s;
    char c;
    cin >> s >> c;
    if (ans[s - 1] == '0') {
      ans[s - 1] = c;
    } else if (ans[s - 1] > c) {
      ans[s - 1] = c;
    }
  }
  if (ans[0] == '0' || ans == "") {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
