#include <bits/stdc++.h>
typedef char string[100];
typedef int array[100];
int intcmp(const void* a, const void* b);
int intcmp2(const void* a, const void* b);
int charcmp(const void* a, const void* b);
int charcmp2(const void* a, const void* b);
int longlongcmp(const void* a, const void* b);
int longlongcmp2(const void* a, const void* b);
bool is_sorted(const int* start, const int* end);
int count(const int* start, const int* end, int target);
void shuffle(int* start, int* end);
void tree_init(void);
int tree_root(int x);
void unite(int x, int y);
bool same(int x, int y);
typedef struct {
  int first;
  int second;
} pair;
int tree[1000];
int cnts = 0;
bool check(int N, int* D) {
  while (N) {
    if (D[N % 10]) return true;
    N /= 10;
  }
  return false;
}
int main(void) {
  int f = 0;
  int N, M;
  int a, b;
  scanf("%d", &N), scanf("%d", &M);
  static char nums[10];
  {
    int size = nums + 10 - nums;
    for (int i = 0; i < size; i++) nums[i] = '0';
  };
  for (int i = 0; i < M; i++) {
    scanf("%d", &a), scanf("%d", &b);
    if (nums[a] == '0') {
      nums[a] = b + '0';
    } else if (nums[a] != b + '0') {
      f = 1;
    }
  }
  if (f || nums[N] == '0')
    printf("%d ", -1);
  else {
    for (int i = 1; i < N + 1; i++) printf("%c", nums[i]);
  }
}
void sort_first(pair* b, pair* e) {
  int* dec;
  int s2 = e - b;
  int size = e - b;
  { dec = (int*)malloc(sizeof(int) * size); };
  for (int i = 0; i < size; i++) dec[i] = b[i].first;
  {
    long long size = dec + s2 - dec;
    qsort(dec, size, sizeof(long long), intcmp);
  };
  for (int i = 0; i < size; i++) b[i].first = dec[i];
}
void sort_second(pair* b, pair* e) {
  int* dec;
  int s2 = e - b;
  int size = e - b;
  { dec = (int*)malloc(sizeof(int) * size); };
  for (int i = 0; i < size; i++) dec[i] = b[i].second;
  {
    long long size = dec + s2 - dec;
    qsort(dec, size, sizeof(long long), intcmp);
  };
  for (int i = 0; i < size; i++) b[i].second = dec[i];
}
int intcmp(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int intcmp2(const void* a, const void* b) { return *(int*)b - *(int*)a; }
int longlongcmp(const void* a, const void* b) {
  return *(long long*)a - *(long long*)b;
}
int longlongcmp2(const void* a, const void* b) {
  return *(long long*)b - *(long long*)a;
}
int charcmp(const void* a, const void* b) { return *(char*)a - *(char*)b; }
int charcmp2(const void* a, const void* b) { return *(char*)b - *(char*)a; }
bool is_sorted(const int* start, const int* end) {
  while (start != end) {
    if (*start > *(start + 1)) return false;
    start++;
  }
  return true;
}
int count(const int* start, const int* end, int target) {
  int cnt = 0;
  int* array;
  int* p;
  array = (int*)malloc((end - start) * sizeof(int));
  if (array == NULL) {
    printf("Err0r");
    exit(-1);
  }
  memcpy(array, start, sizeof(int) * (end - start));
  {
    long long size = array + (end - start) - array;
    qsort(array, size, sizeof(long long), intcmp);
  };
  p = (int*)bsearch(&target, array, end - start, sizeof(int), intcmp);
  if (p == NULL) {
    free(array);
    return 0;
  }
  while (*p == target) p++;
  p--;
  while (*p == target) {
    cnt++;
    p--;
  }
  free(array);
  return cnt;
}
void shuffle(int* start, int* end) {
  srand((unsigned)time(NULL));
  int a, b;
  int size = end - start;
  for (int i = 0; i < 500; i++) {
    a = (0) + (rand()) % ((size - 1) - (0) + (1));
    b = (0) + (rand()) % ((size - 1) - (0) + (1));
    ((start[a] != start[b]) &&
     (start[a] += start[b], start[b] = start[a] - start[b],
      start[a] -= start[b]));
  }
}
void tree_init(void) {
  for (int i = 0; i < 1000; i++) tree[i] = i;
}
int tree_root(int x) {
  if (tree[x] == x) return x;
  return tree[x] = tree_root(tree[x]);
}
void unite(int x, int y) {
  int rx = tree_root(x);
  int ry = tree_root(y);
  if (rx == ry) return;
  tree[rx] = ry;
}
bool same(int x, int y) {
  int rx = tree_root(x);
  int ry = tree_root(y);
  return rx == ry;
}
long long pow_mod(long long n, long long k, long long m) {
  if (k == 0)
    return 1;
  else if (k % 2)
    return pow_mod(n, k - 1, m) * n % m;
  else {
    int t = pow_mod(n, k / 2, m);
    return t * t % m;
  }
}
