#include <bits/stdc++.h>
using namespace std;
int 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];
  string ans = "";
  for (int i = 0; i < (n); i++) ans += '0';
  bool flag = true;
  vector<bool> a(n);
  for (int i = 0; i < (m); i++) {
    if (a[s[i] - 1] == false) {
      a[s[i] - 1] == true;
      ans[s[i] - 1] = c[i];
    } else {
      if (ans[s[i] - 1] != c[i]) flag = false;
    }
  }
  if (ans[0] == '0') flag = false;
  if (flag)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
