#include <bits/stdc++.h>
long int combination(long int n, long int r);
int compare_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }
long int combination(long int n, long int r) {
  if (r > n - r) r = n - r;
  if (r == 0)
    return 1;
  else if (r == 1)
    return n;
  return (combination(n - 1, r) + combination(n - 1, r - 1));
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &s[i], &c[i]);
  }
  int num[n + 1];
  num[0] = 1;
  for (int i = 1; i <= n; i++) {
    num[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    if (num[s[i]] == -1) {
      num[s[i]] = c[i];
    } else {
      num[0] = -1;
    }
  }
  if (num[1] == 0) num[0] = -1;
  if (num[1] == -1) num[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (num[i] == -1) num[i] = 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = ans * 10 + num[i];
  }
  if (num[0] == 1)
    printf("%d\n", ans);
  else
    printf("-1\n");
  return 0;
}
