#include <bits/stdc++.h>
void c(std::istream& in) {
  int N, M;
  in >> N >> M;
  struct sc {
    int s;
    int c;
  };
  std::vector<sc> scList(M);
  for (auto& sc : scList) {
    in >> sc.s >> sc.c;
  }
  std::vector<int> num(N, 10);
  for (const auto& sc : scList) {
    if (num[static_cast<size_t>(sc.s) - 1] > sc.c)
      num[static_cast<size_t>(sc.s) - 1] = sc.c;
  }
  for (auto& n : num) {
    if (n == 10) n = 0;
  }
  if ((num[static_cast<size_t>(N) - 1] == 0) and (N >= 2)) {
    std::cout << -1;
    return;
  }
  int result = 0;
  for (int i = 0; i < N; ++i) {
    result += num[i] * static_cast<int>(std::pow(10, N - i - 1));
  }
  std::cout << result;
}
int main(int, char*[]) {
  c(std::cin);
  return 0;
}
