#include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
  int n, m;
  scanf("%d%d", &n, &m);
  int num[n + 1];
  for (int i = 0; i < n + 1; i++) {
    num[i] = 10;
  }
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &s[i], &c[i]);
    if (s[i] == 1 && c[i] == 0 && n > 1) {
      printf("-1");
      return 0;
    }
    if (num[s[i]] < 10 && num[s[i]] != c[i]) {
      printf("-1");
      return 0;
    }
    num[s[i]] = c[i];
  }
  for (int i = 2; i < n + 1; i++) {
    if (num[i] == 10) num[i] = 0;
  }
  if (num[1] == 10) num[1] = 1;
  for (int i = 1; i < n + 1; i++) {
    printf("%d", num[i]);
  }
  return 0;
}
