#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000;
long long int mod = 1e9 + 7;
int main() {
  int n, m;
  char a[5];
  string ans = "ABC";
  cin >> n >> m;
  fill(a, a + 5, 'A');
  for (long long int i = 0; i < m; i++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    if (a[s] == 'A')
      a[s] = c;
    else {
      if (a[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 2; i >= 0; i--) {
    if (a[i] != 'A') {
      if (ans == "ABC")
        ans = a[i];
      else
        ans = a[i] + ans;
    } else {
      if (ans != "ABC") ans = '0' + ans;
    }
  }
  if (ans[ans.size() - 1] == '0') ans = '1' + ans;
  if (ans.size() == n)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
