#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string ans(n, '0');
  set<int> hoge;
  set<char> fuga;
  for (int i = 0; i < m; i++) {
    int s;
    cin >> s;
    char c;
    cin >> c;
    ans.at(s - 1) = c;
    hoge.insert(s);
    fuga.insert(c);
  }
  if (hoge.size() == fuga.size() && ans.at(0) != '0')
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
