#include <bits/stdc++.h>
int GuessNumber(int n, const std::vector<std::pair<int, int>> &conditions) {
  if (n > 1) {
    auto illegal_pair = std::make_pair(1, 0);
    for (const auto &condition : conditions) {
      if (condition == illegal_pair) return -1;
    }
  }
  std::vector<int> results(n, -1);
  for (const auto &condition : conditions) {
    auto digit = condition.first;
    auto num = condition.second;
    if (results[n - digit] >= 0 && results[n - digit] != num) return -1;
    results[n - digit] = num;
  }
  auto number = 0;
  for (int i = 0; i < (int)(n); ++i) {
    auto x = results[i];
    if (x != -1) number += std::pow(10, i) * x;
  }
  return number;
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int n, m, s, c;
  std::vector<std::pair<int, int>> conditions;
  std::cin >> n >> m;
  for (int i = 0; i < (int)(m); ++i) {
    std::cin >> s >> c;
    conditions.emplace_back(std::make_pair(s, c));
  }
  std::cout << GuessNumber(n, conditions) << "\n";
}
