#include <bits/stdc++.h>
int main() {
  int n, m, cnt = 0;
  scanf("%d", &n);
  scanf("%d", &m);
  int s[m], c[m], num[n];
  for (int i = 0; i < n; i++) num[i] = 10;
  for (int i = 0; i < m; i++) {
    scanf("%d", &s[i]);
    scanf("%d", &c[i]);
  }
  for (int i = 0; i < m; i++) {
    if (num[n - s[i]] == 10 || num[n - s[i]] == c[i])
      num[n - s[i]] = c[i];
    else
      cnt++;
  }
  for (int i = 0; i < n; i++)
    if (num[i] == 10) num[i] = 0;
  if ((num[n - 1] == 0 && n != 1) || cnt > 0)
    printf("-1\n");
  else if (n == 1 && num[n - 1] == 0 && cnt == 0)
    printf("0\n");
  else {
    for (int i = 1; i <= n; i++) printf("%d", num[n - i]);
    printf("\n");
  }
}
