#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int a[n], u[n], cant = false;
  memset(a, 0, sizeof(a));
  memset(u, 0, sizeof(u));
  for (int i = 0; i < m; i++) {
    int s, c;
    scanf("%d %d", &s, &c);
    s--;
    if (n != 1 && s == 0 && c == 0) cant = true;
    if (u[s] && a[s] != c)
      cant = true;
    else {
      a[s] = c;
      u[s] = true;
    }
  }
  if (!u[0]) a[0] = 1;
  if (cant)
    puts("-1");
  else {
    for (int i = 0; i < n; i++) printf("%d", a[i]);
    puts("");
  }
  return 0;
}
