#include <bits/stdc++.h>
using namespace std;
int x[100];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int a, b;
  for (int i = 1; i <= n; i++) x[i] = 11;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    if (x[a] == 11 || x[a] == b) {
      x[a] = b;
    } else {
      printf("-1\n");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%d", x[i] % 10);
  }
  printf("\n");
  return 0;
}
