#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[10];
int all, bll;
int gl;
int main(void) {
  scanf("%d %d", &n, &m);
  a[3] = -1;
  a[1] = -1;
  a[2] = -1;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &all, &bll);
    if (a[all] == -1) {
      a[all] = bll;
    } else if (a[all] != bll) {
      printf("-1");
      return 0;
    } else if (a[all] == bll)
      a[all] = bll;
  }
  if (a[1] == -1) a[1] = 1;
  if (a[1] == 0 && n >= 2) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1)
      printf("0");
    else
      printf("%d", a[i]);
  }
  return 0;
}
