#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
template <typename V1, typename V2>
using pair = std::pair<V1, V2>;
using str = std::string;
template <typename Val, std::size_t Size>
using arr = std::array<Val, Size>;
template <typename Val>
using vec = std::vector<Val>;
template <typename Val>
using list = std::list<Val>;
template <typename Val>
using stack = std::stack<Val>;
template <typename Val>
using queue = std::queue<Val>;
template <typename Val>
using pqueue = std::priority_queue<Val>;
template <typename Val>
using deque = std::deque<Val>;
template <typename Key, typename Val>
using map = std::map<Key, Val>;
template <typename Key, typename Val>
using mmap = std::multimap<Key, Val>;
template <typename Key, typename Val>
using umap = std::unordered_map<Key, Val>;
template <typename Key, typename Val>
using ummap = std::unordered_multimap<Key, Val>;
template <typename Key, typename Val>
using set = std::set<Key, Val>;
template <typename Key, typename Val>
using mset = std::multiset<Key, Val>;
template <typename Key, typename Val>
using uset = std::unordered_set<Key, Val>;
template <typename Key, typename Val>
using umset = std::unordered_multiset<Key, Val>;
const str ln = "\n";
int main() {
  ull N, M, result = 0, digit_max = 0;
  std::cin >> N >> M;
  vec<ull> s(M), c(M), value(N, 0);
  value.at(0) = 1;
  for (ull i = 0; i != M; ++i) {
    std::cin >> s.at(i) >> c.at(i);
  }
  for (ull i = 0; i != M; ++i) {
    if (digit_max < s.at(i)) digit_max = s.at(i);
    if (s.at(i) == 1) {
      if (value.at(0) == 1) {
        value.at(0) = c.at(i);
      } else if (value.at(0) != c.at(i)) {
        std::cout << -1 << ln;
        return 0;
      }
    } else {
      if (value.at(s.at(i) - 1) == 0) {
        value.at(s.at(i) - 1) = c.at(i);
      } else if (value.at(s.at(i) - 1) != c.at(i)) {
        std::cout << -1 << ln;
        return 0;
      }
    }
  }
  if (N > 1 && value.at(0) == 0) {
    std::cout << -1 << ln;
    return 0;
  }
  for (ull i = 0; i != N; ++i) {
    std::cout << value.at(i);
  }
  std::cout << ln;
}
