#include <bits/stdc++.h>
int solve() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> s(M);
  std::vector<int> c(M);
  for (int i = 0; i < M; ++i) std::cin >> s[i] >> c[i];
  for (int i = 0; i < M; ++i)
    for (int j = i; j < M; ++j)
      if (s[i] == s[j] && c[i] != c[j]) return -1;
  std::set<std::pair<int, int>> p;
  for (int i = 0; i < M; ++i) p.insert(std::pair<int, int>(s[i], c[i]));
  int ans = 0;
  for (auto itr = p.begin(); itr != p.end(); ++itr)
    ans += std::pow(10, N - itr->first) * itr->second;
  if (ans / std::pow(10, N - 1) == 0) ans = -1;
  return ans;
}
int main() {
  std::cout << solve() << std::endl;
  return 0;
}
