#include <bits/stdc++.h>
template <std::uint_fast64_t Modulus>
class modint {
  using u64 = std::uint_fast64_t;

 public:
  u64 a;
  modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  u64 &value() noexcept { return a; }
  const u64 &value() const noexcept { return a; }
  modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
int main(void) {
  int n, m;
  std::cin >> n >> m;
  static int MAX_VAL = std::pow(10, n) - 1;
  std::set<std::pair<int, int> > s_c;
  for (int i = 0; i < m; i++) {
    int s, c;
    std::cin >> s >> c;
    s_c.insert(std::make_pair(s, c));
  }
  for (int i = 0; i <= MAX_VAL; i++) {
    int keta = std::log10(i) + 1;
    bool flag = true;
    for (const auto &elem : s_c) {
      int s = elem.first;
      int c = elem.second;
      if (keta < s) flag = false;
      int tmp = i;
      for (int j = keta; j > s; j--) {
        tmp /= 10;
      }
      if (tmp % 10 != c) flag = false;
      if (flag == false) break;
    }
    if (flag) {
      std::cout << i << std::endl;
      return 0;
    }
  }
  std::cout << -1 << std::endl;
  return 0;
}
