#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  string s;
  s.append(n, '0');
  map<long long, char> mp;
  for (long long i = 0; i < m; i++) {
    long long pos;
    char ch;
    cin >> pos >> ch;
    pos--;
    if (mp[pos] != ch and mp[pos] != '\0') {
      cout << -1;
      return 0;
    }
    mp[pos] = ch;
  }
  for (auto it : mp) {
    s[it.first] = it.second;
  }
  if (s[0] == '0')
    cout << -1;
  else
    cout << s;
}
