#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
int main() {
  int n, m, i, a;
  char b;
  cin >> n >> m;
  string s(n, '0');
  while (m--) {
    cin >> a >> b;
    s[a - 1] = min(s[a - 1], b);
  }
  if (s[0] == '0') {
    cout << -1 << '\n';
  } else
    cout << s << '\n';
}
