#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  bool d = false;
  std::vector<int> a(n, 10);
  for (int i = 0; i < m; ++i) {
    int s, c;
    std::cin >> s >> c;
    if (a.at(s - 1) != 10 && a.at(s - 1) != c) {
      d = true;
    }
    a.at(s - 1) = c;
  }
  if (d) {
    std::cout << -1 << std::endl;
    return 0;
  }
  if (n == 1 && a.at(0) == 0) {
    std::cout << 0 << std::endl;
    return 0;
  }
  if (a.at(0) == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }
  for (const auto &v : a) {
    if (v == 10) {
      std::cout << 0;
    } else {
      std::cout << v;
    }
  }
  std::cout << std::endl;
  return 0;
}
