#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ans;
  int a;
  char b;
  char ch[3] = {'a', 'a', 'a'};
  cin >> M >> M;
  for (int i = 0; i < (M); i++) {
    cin >> a >> b;
    a--;
    if (ch[a] == 'a' || ch[a] == b) {
      ch[a] = b;
    } else {
      printf("-1");
      return 0;
    }
  }
  int cnt = 0;
  for (int i = 0; i < (3); i++) {
    if (ch[i] == '0' && cnt == 0) {
      printf("-1");
      return 0;
    } else if (ch[i] == 'a' && cnt == 1)
      printf("0");
    else if (ch[i] == 'a' && cnt == 0)
      continue;
    else {
      printf("%c", ch[i]);
      cnt = 1;
    }
  }
}
