#include <bits/stdc++.h>
using namespace std;
void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}
void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
void Main() {
  int n, m;
  _cin(n, m);
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  for (int i = 0; i < (m); ++i) {
    for (int j = i + 1; j < m; ++j) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return;
      }
    }
  }
  string ans(n, '0');
  for (int i = 0; i < (m); ++i) ans[s[i] - 1] = c[i];
  if (ans[0] == '0') {
    cout << -1 << endl;
    return;
  }
  cout << ans << endl;
}
