#include <bits/stdc++.h>
using namespace std;
long long n, M;
bool b[3];
map<long long, char> m;
string ans;
signed main() {
  cin >> n >> M;
  for (long long i = 0; i < (long long)(n); ++i) m[i] = '0';
  for (long long i = 0; i < (long long)(M); ++i) {
    long long s;
    char c;
    cin >> s >> c;
    --s;
    if (b[s]) {
      if (m[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      b[s] = true;
      m[s] = c;
    }
  }
  for (auto i : m) ans.push_back(i.second);
  if (ans[0] == '0' && ans.size() != 1)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
