#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::terminate;
void solve() {
  int n, m;
  cin >> n >> m;
  string str;
  str.append(n, '0');
  for (int a = 1; a <= m; ++a) {
    int s;
    cin >> s;
    s--;
    char c;
    cin >> c;
    if (str[s] == '0' || str[s] > c) {
      str[s] = c;
    }
  }
  if (str[0] == '0') {
    cout << -1 << endl;
  } else {
    cout << str << endl;
  }
}
int main() {
  solve();
  return 0;
}
