#include <bits/stdc++.h>
int main() {
  std::string ans(3, '0');
  bool flag[3] = {false};
  size_t n, m;
  std::cin >> n >> m;
  for (size_t i = 0; i < m; i++) {
    size_t s;
    char c;
    std::cin >> s >> c;
    if (flag[s - 1] && (ans[s - 1] != c)) {
      std::cout << -1 << std::endl;
      return 0;
    } else {
      ans[s - 1] = c;
      flag[s - 1] = true;
    }
  }
  size_t num = std::stoi(ans);
  if (std::to_string(num).size() < n) {
    std::cout << std::pow(10, (3 - std::to_string(num).size())) + num
              << std::endl;
  } else if (std::to_string(num).size() == n) {
    std::cout << num << std::endl;
  } else {
    for (size_t i = 0; i < n; i++) {
      std::cout << std::to_string(num).at(i);
    }
    std::cout << std::endl;
  }
  return 0;
}
