#include <bits/stdc++.h>
int main() {
  int64_t N, M;
  std::cin >> N >> M;
  std::string str = "000";
  int64_t max = 0;
  for (int64_t i = 0; i < M; ++i) {
    int64_t s;
    char c;
    std::cin >> s >> c;
    s--;
    if (s > max) max = s;
    str.at(s) = c;
  }
  if (max != N - 1) {
    std::cout << -1 << std::endl;
  } else {
    std::cout << std::atoi(str.c_str()) << std::endl;
  }
  return 0;
}
