#include <bits/stdc++.h>
#pragma warning(disable : 4996)
int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);
int _gcd(int a, int b);
int _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
int s_asorts(const void* a, const void* b);
int s_asorts(const void* a, const void* b) {
  return (strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) { return (*(int*)b - *(int*)a); }
int s_asort(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int l_cins2(int n, long* a, long* b) {
  int i;
  for (int i = 0; i < n; i++) {
    scanf("%ld %ld", &*(a + i), &*(b + i));
  }
  return 0;
}
int i_cins(int n, int* a) {
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &*(a + i));
  }
  return 0;
}
int _gcd(int a, int b) {
  int r, tmp;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while (r) {
    if (!r) break;
    a = b;
    b = r;
    r = a % b;
  }
  return (b);
}
long _max(long a, long b) { return a > b ? a : b; }
long _min(long a, long b) { return a < b ? a : b; }
int _swp(int* a, int* b) {
  int tmp;
  tmp = *b;
  *b = *a;
  *a = tmp;
  return 0;
}
int _cknum(char* a, int n) {
  int i;
  char t = '0';
  for (i = 0; i < n; i++) {
    if (a[i] < '0' || a[i] > '9') return 1;
  }
  return 0;
}
int _atoi(char* s, int len) {
  char tmp[20];
  memcpy(tmp, s, len);
  tmp[len] = 0x00;
  return (atoi(tmp));
}
long long _pfact(long long a);
static long long pf[100000000];
static long long pc;
long long _pfact(long long a) {
  long i, r;
  if (a % 2 == 0) {
    pf[pc] = 2;
    pc++;
    return (_pfact(a / 2));
  }
  r = sqrt(a);
  for (i = 3; i <= r; i += 2) {
    if (a % i == 0) {
      pf[pc] = i;
      pc++;
      return (_pfact(a / i));
    }
  }
  if (a != 1) {
    pf[pc] = a;
    pc++;
  }
  return 0;
}
int main(void) {
  int n, m;
  int s, c;
  char a[4] = {'*', '*', '*', 0x00};
  int i, ans = 0;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &s, &c);
    if (a[s - 1] == (char)c + '0') continue;
    if (a[s - 1] != '*') {
      printf("%d\n", -1);
      return 0;
    }
    a[s - 1] = (char)c + '0';
  }
  if ((n == 3 && a[0] == '0') || (n == 2 && a[1] == '0')) {
    printf("%d\n", -1);
    return 0;
  }
  for (i = 0; i < 3; i++)
    if (a[i] == '*') a[i] = '0';
  ans = atoi(&a[3 - n]);
  printf("%d\n", ans);
  return 0;
}
