#include <bits/stdc++.h>
void swap(int* a, int* b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}
int abs(int a) {
  if (a < 0) return -a;
  return a;
}
int dup(int a, int d) {
  if (a % d == 0)
    return a / d;
  else
    return a / d + 1;
}
int mod(int a, int m) {
  if (a < 0)
    return a % m + m;
  else
    return a % m;
}
void swapl(long long* a, long long* b) {
  long long tmp = *a;
  *a = *b;
  *b = tmp;
}
long long absl(long long a) {
  if (a < 0) return -a;
  return a;
}
long long dupl(long long a, long long d) {
  if (a % d == 0)
    return a / d;
  else
    return a / d + 1;
}
long long modl(long long a, long long m) {
  if (a < 0)
    return a % m + m;
  else
    return a % m;
}
long long GCD(long long a, long long b) {
  long long c = 1, tmp = ((a) < (b) ? (b) : (a));
  b = ((a) < (b) ? (a) : (b));
  a = tmp;
  while (c != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
long long factorial(long long n, long long m) {
  return n < m ? 1 : n * factorial(n - 1, m);
}
int upll(const void* a, const void* b) {
  return *(long long*)a < *(long long*)b   ? -1
         : *(long long*)a > *(long long*)b ? 1
                                           : 0;
}
int downll(const void* a, const void* b) {
  return *(long long*)a < *(long long*)b   ? 1
         : *(long long*)a > *(long long*)b ? -1
                                           : 0;
}
void sortup(long long* a, int n) { qsort(a, n, sizeof(long long), upll); }
void sortdown(long long* a, int n) { qsort(a, n, sizeof(long long), downll); }
int main() {
  long long n, m;
  long long s[10];
  char str[10], c[10];
  scanf("%lld%lld", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%lld%c", s + i, c + i);
  }
  for (int i = 0; i < 10; i++) {
    str[i + 1] = '\0';
  }
  for (int i = 0; i < m; i++) {
    if (str[s[i]] != '\0' && str[s[i]] != c[i]) {
      printf("-1\n");
      return 0;
    }
    str[s[i]] = c[i];
  }
  if (str[1] == 0 && n != 1) {
    printf("-1\n");
  }
  if (str[1] == '\0') {
    str[1] = 1;
  }
  for (int i = 2; i <= n; i++) {
    if (str[i] == '\0') str[i] = '0';
  }
  printf("%s\n", str + 1);
  return 0;
}
