#include <bits/stdc++.h>
using namespace std;
void swap(int *a, int *b) {
  *b = *a - *b;
  *a -= *b;
  *b += *a;
}
int sosu_judge(int N) {
  int i, j;
  if (N == 2) return 1;
  if (N % 2 == 0) return 0;
  for (i = 3; i < N && N % i != 0; i += 2)
    ;
  if (i >= N) return 1;
  return 0;
}
int factorial(int N) {
  int ans = 1;
  while (N--) ans *= (N + 1);
  return ans;
}
void q_sort(int a[], int first, int last) {
  int i, j;
  int x, t;
  x = a[(first + last) / 2];
  i = first;
  j = last;
  while (1) {
    while (a[i] < x) i++;
    while (x < a[j]) j--;
    if (i >= j) break;
    swap(&a[i], &a[j]);
    i++;
    j--;
  }
  if (first < i - 1) q_sort(a, first, i - 1);
  if (last > j + 1) q_sort(a, j + 1, last);
}
int b_search(int target, int array[], int right, int left) {
  int mid;
  while (left < right) {
    mid = (right + left) / 2;
    if (array[mid] < target)
      left = mid + 1;
    else
      right = mid;
  }
  if (array[mid] == target) return mid;
  return -1;
}
unsigned long combination(int n, int r) {
  int i, j;
  unsigned long a[17];
  if (n - r < r) r = n - r;
  if (r == 0) return 1;
  if (r == 1) return n;
  if (r > 17) return 0;
  for (i = 1; i < r; i++) a[i] = i + 2;
  for (i = 3; i <= n - r + 1; i++) {
    a[0] = i;
    for (j = 1; j < r; j++) a[j] += a[j - 1];
  }
  return a[r - 1];
}
int main() {
  int N, M;
  cin >> N >> M;
  int S[M];
  char C[M];
  int count = 0;
  char ans[4];
  for (int i = 0; i < (int)(M); i++) {
    cin >> S[i] >> C[i];
  }
  for (int i = 0; i < (int)(N); i++) {
    ans[i] = 'a';
  }
  for (int i = 0; i < (int)(M); i++) {
    if (ans[S[i] - 1] != 'a' && ans[S[i] - 1] != C[i]) {
      cout << "-1" << endl;
      return 0;
    }
    if (ans[S[i] - 1] == 'a') ans[S[i] - 1] = C[i];
  }
  for (int i = 0; i < (int)(N); i++) {
    if (ans[i] == 'a') ans[i] = '0';
  }
  if (ans[0] == '0') {
    cout << "-1" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
