#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, string>> s(m);
  vector<string> ans(n, "0");
  for (int i = 0; i < (m); i++) {
    cin >> s[i].first >> s[i].second;
    s[i].first--;
  }
  sort(s.begin(), s.end());
  bool ok = true;
  for (int i = 1; i <= (n - 1); i++) {
    if (s[i].first == s[i - 1].first && s[i].second != s[i - 1].second)
      ok = false;
  }
  if (ok) {
    for (int i = 0; i < (m); i++) ans[s[i].first] = s[i].second;
    if (ans[0] == "0")
      cout << -1;
    else
      for (int i = 0; i < (n); i++) cout << ans[i];
  } else
    cout << -1 << endl;
}
