#include <bits/stdc++.h>
int main() {
  bool flag_finish = false;
  int N_MAX = 3;
  int N, M;
  std::cin >> N >> M;
  std::vector<int> s(M);
  std::vector<int> c(M);
  std::vector<int> sc(N_MAX + 1, -1);
  for (int i = 0; i < M; i++) {
    std::cin >> s[i] >> c[i];
    if (N >= 2 && s[i] == 1 && c[i] == 0) flag_finish = true;
    if (sc[s[i]] == -1)
      sc[s[i]] = c[i];
    else if (sc[s[i]] != c[i])
      flag_finish = true;
    if (s[i] > N) flag_finish = true;
  }
  if (flag_finish == true)
    std::cout << -1 << std::endl;
  else {
    std::vector<int> v(N, 0);
    for (int i = 0; i < M; i++) v[s[i] - 1] = c[i];
    if (v[0] == 0) v[0] = 1;
    std::string ans = "";
    for (int i = 0; i < N; i++) ans += std::to_string(v[i]);
    std::cout << std::stoi(ans) << std::endl;
  }
  return 0;
}
