#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[10];
bool boo = true;
int main() {
  int i, j, k;
  memset(a, -1, sizeof(a));
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (a[x] == -1)
      a[x] = y;
    else if (a[x] != y)
      boo = false;
  }
  if (n == 1) {
    if (!boo) printf("-1\n");
    if (a[1] == -1)
      printf("0\n");
    else
      printf("%d\n", a[1]);
    return 0;
  }
  if (a[1] == 0) boo = false;
  if (!boo)
    printf("-1\n");
  else {
    for (i = 1; i <= n; i++)
      if (a[i] != -1)
        printf("%d", a[i]);
      else if (i == 1)
        printf("1");
      else
        printf("0");
  }
}
