#include <bits/stdc++.h>
int GuessNumber(int n, const std::vector<std::pair<int, int>> &conditions) {
  int res = -1;
  for (int num = 999; num >= 0; --num) {
    std::string num_str = std::to_string(num);
    bool is_ok = true;
    if (num_str.size() != n) break;
    for (const auto &condition : conditions) {
      int s = condition.first;
      int c = condition.second;
      if (num_str[s - 1] != (char)('0' + c)) {
        is_ok = false;
        break;
      }
    }
    if (is_ok) res = num;
  }
  return res;
}
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";
}
