#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[5], b[5], i, j, x;
  char s[3] = {'a', 'b', 'c'};
  cin >> n >> m;
  for (i = 0; i < m; i++) cin >> a[i] >> b[i];
  for (i = 0; i < m; i++) {
    if (a[i] == 1 && b[i] != 0) {
      s[0] = b[i];
      break;
    }
  }
  for (i = 0; i < m; i++)
    if (a[i] == 2 || a[i] == 3) {
      x = a[i];
      s[x] = b[i];
    }
  for (i = 1; i < 3; i++)
    if (s[i] == 'b' || s[i] == 'c') s[i] = '0';
  if (s[0] == 'a')
    cout << "-1";
  else
    for (i = 0; i < 3; i++) cout << s[i];
}
