#include <bits/stdc++.h>
using V = std::vector<std::pair<int, int>>;
int solve(int n, int m, V& v) {
  std::string num(n, '-');
  for (const auto& p : v) {
    const auto s = p.first - 1;
    const auto c = p.second;
    const auto c_char = std::to_string(c)[0];
    if (num[s] == '-') {
      num[s] = c_char;
    } else if (num[s] != c_char) {
      return -1;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (num[i] == '-') num[i] = '0';
  }
  if (num[0] == '0' && n >= 2) return -1;
  return std::stoi(num);
}
int main() {
  int n, m;
  std::cin >> n >> m;
  V v(m);
  for (auto& p : v) {
    std::cin >> p.first >> p.second;
  }
  std::cout << std::setprecision(20);
  std::cout << solve(n, m, v) << std::endl;
}
