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