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