#include <bits/stdc++.h>
using namespace std;
int a[10];
int main() {
  int n, m;
  memset(a, -1, sizeof(-1));
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int s, c;
    cin >> s >> c;
    if (a[s] != -1 && a[s] != c) {
      printf("-1\n");
      return 0;
    } else
      a[s] = c;
  }
  if (n > 1 && a[1] == 0)
    printf("-1\n");
  else if (n == 1) {
    if (a[1] == -1)
      printf("0\n");
    else
      printf("%d\n", a[1]);
  } else {
    for (int i = 1; i <= n; i++) {
      if (i == 1 && a[i] == -1)
        printf("1");
      else if (a[i] == -1)
        printf("0");
      else
        printf("%d", a[i]);
    }
    printf("\n");
  }
  return 0;
}
