#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  string ans(N, '0');
  for (int i = 0; i < M; ++i) {
    long long s;
    char c;
    cin >> s >> c;
    if (ans[s - 1] == '0')
      ans[s - 1] = c;
    else {
      if (ans[s - 1] == c) {
        continue;
      }
      cout << "-1" << endl;
      return 0;
    }
  }
  if (ans[0] == '0')
    cout << "-1" << endl;
  else
    cout << ans << endl;
}
