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