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