#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) s += '0';
  for (int i = 0; i < m; i++) {
    int a;
    char b;
    cin >> a >> b;
    if (s[a - 1] > b) s[a - 1] = b;
  }
  if (n >= 2 and s[0] == '0')
    cout << -1 << endl;
  else
    cout << s << endl;
}
