#include <bits/stdc++.h>
using namespace std;
int main() {
  bitset<3> checker;
  int N, M;
  cin >> N >> M;
  string res(N, '0');
  for (int m = 0; m < M; ++m) {
    int s;
    char c;
    cin >> s >> c;
    --s;
    if (checker.test(s)) {
      if (res[s] != c) {
        cout << "-1" << endl;
        return 0;
      }
    } else {
      checker.set(s);
      res[s] = c;
    }
  }
  if (res.size() != 1 && res[0] == '0') {
    cout << "-1" << endl;
    return 0;
  }
  cout << res << endl;
  return 0;
}
