#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> s(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i].first >> s[i].second;
  }
  vector<char> Ans(N);
  bool T = false;
  sort(s.begin(), s.end());
  for (int i = 0; i < M - 1; i++) {
    if ((s[i].first == s[i + 1].first) && (s[i].second != s[i + 1].second))
      T = true;
  }
  for (int i = 0; i < N; i++) {
    Ans[i] = '0';
  }
  for (int i = 0; i < M; i++) {
    Ans[s[i].first - 1] = s[i].second;
  }
  if (T || Ans[0] == '0')
    cout << -1 << endl;
  else {
    for (int i = 0; i < N; i++) {
      cout << Ans[i];
    }
    cout << endl;
  }
}
