#include <bits/stdc++.h>
using ConditonType = std::map<int, int>;
int ExtractDigit(int value, int targetDigit) {
  if (targetDigit == 1) {
    return value % 10;
  }
  return ExtractDigit(value / 10, targetDigit - 1);
}
bool IsMatchCondition(int value, const ConditonType& condition) {
  for (const auto& current : condition) {
    if (ExtractDigit(value, current.first) != current.second) {
      return false;
    }
  }
  return true;
}
int main() {
  int answerDigit = 0;
  std::cin >> answerDigit;
  int conditionCount = 0;
  std::cin >> conditionCount;
  ConditonType condition;
  for (auto count = 0; count < conditionCount; ++count) {
    int inputDigit = 0;
    std::cin >> inputDigit;
    const auto digit = answerDigit + 1 - inputDigit;
    int value = 0;
    std::cin >> value;
    auto prev = condition.find(digit);
    if (prev != condition.end()) {
      if (prev->second != value) {
        std::cout << -1;
        return 0;
      }
    } else {
      condition.insert(std::make_pair(digit, value));
    }
  }
  const auto startAnswer = static_cast<int>(std::pow(10, answerDigit - 1));
  const auto maxAnswer = static_cast<int>(std::pow(10, answerDigit));
  for (auto answer = startAnswer; answer < maxAnswer; ++answer) {
    if (IsMatchCondition(answer, condition)) {
      std::cout << answer;
      return 0;
    }
  }
  std::cout << -1;
  return 0;
}
