#include <bits/stdc++.h>
int n, m, nyaa[9] = {-1, -1, -1, -1}, a, b;
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    scanf("%d%d", &a, &b);
    a--;
    if (nyaa[a] < 0)
      nyaa[a] = b;
    else {
      if (nyaa[a] != b) {
        puts("-1");
        return 0;
      }
    }
  }
  if (nyaa[0] == 0) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (nyaa[i] < 0) {
      putchar(49 - (i > 0));
    } else {
      putchar(48 + nyaa[i]);
    }
  }
  putchar(10);
  return 0;
}
