#include <bits/stdc++.h>
using namespace std;
template <typename T>
void MACRO_VAR_Scan(T &t) {
  std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &...rest) {
  std::cin >> first;
  MACRO_VAR_Scan(rest...);
}
template <typename T>
void MACRO_VEC_ROW_Init(int n, T &t) {
  t.resize(n);
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) {
  first.resize(n);
  MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T>
void MACRO_VEC_ROW_Scan(int p, T &t) {
  std::cin >> t[p];
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) {
  std::cin >> first[p];
  MACRO_VEC_ROW_Scan(p, rest...);
}
template <typename T>
void MACRO_OUT(const T t) {
  std::cout << t;
}
template <typename First, typename... Rest>
void MACRO_OUT(const First first, const Rest... rest) {
  std::cout << first << " ";
  MACRO_OUT(rest...);
}
template <class T>
inline T CHMAX(T &a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T CHMIN(T &a, const T b) {
  return a = (a > b) ? b : a;
}
template <class T>
using V = std::vector<T>;
template <class T>
using VV = V<V<T>>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<ll, ll>;
using PAIRLL = std::pair<ll, ll>;
constexpr ll INFINT = (1 << 30) - 1;
constexpr ll INFINT_LIM = (1LL << 31) - 1;
constexpr ll INFLL = 1LL << 60;
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);
constexpr double eps = 1e-7;
constexpr ll MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template <class T, size_t N>
void FILL(T (&a)[N], const T &val) {
  for (auto &x : a) x = val;
}
template <class ARY, size_t N, size_t M, class T>
void FILL(ARY (&a)[N][M], const T &val) {
  for (auto &b : a) FILL(b, val);
}
template <class T>
void FILL(std::vector<T> &a, const T &val) {
  for (auto &x : a) x = val;
}
template <class ARY, class T>
void FILL(std::vector<std::vector<ARY>> &a, const T &val) {
  for (auto &b : a) FILL(b, val);
}
template <ll mod>
struct ModInt {
  ll x;
  ModInt() : x(0) {}
  ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (ll)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt &operator^=(long long p) {
    ModInt res = 1;
    for (; p; p >>= 1) {
      if (p & 1) res *= *this;
      *this *= *this;
    }
    return *this = res;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  ModInt operator^(long long p) const { return ModInt(*this) ^= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  explicit operator ll() const { return x; }
  ModInt operator=(const ll p) {
    x = p;
    return ModInt(*this);
  }
  ModInt inverse() const {
    ll a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      a -= t * b;
      std::swap(a, b);
      u -= t * v;
      std::swap(u, v);
    }
    return ModInt(u);
  }
  friend std::ostream &operator<<(std::ostream &os, const ModInt<mod> &p) {
    return os << p.x;
  }
  friend std::istream &operator>>(std::istream &is, ModInt<mod> &a) {
    long long x;
    is >> x;
    a = ModInt<mod>(x);
    return (is);
  }
};
ModInt<MOD> combination(ull s, ull r) {
  if (r * 2 > s) r = s - r;
  ModInt<MOD> dividend = 1;
  ModInt<MOD> divisor = 1;
  for (ull i = 1; i <= r; ++i) {
    dividend *= (s - i + 1);
    divisor *= i;
  }
  return dividend / divisor;
}
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  ll n, m;
  MACRO_VAR_Scan(n, m);
  ;
  std::vector<std::vector<ll>> sc_list(m, std::vector<ll>(2));
  for (auto &R : sc_list)
    for (auto &w : R) std::cin >> w;
  ;
  ll a = 0;
  ll tmp = 9;
  vector<ll> min_int(n);
  string min_string;
  bool f_found = 0;
  for (ll j = 0; j < ll(n); ++j) {
    min_int[j] = 0;
    f_found = 0;
    for (ll i = 0; i < ll(m); ++i) {
      if (sc_list[i][0] == j + 1) {
        CHMIN(tmp, sc_list[i][1]);
        f_found = 1;
      }
    }
    if (f_found == 0) {
      tmp = 0;
    }
    min_int[j] = tmp;
    tmp = 9;
  }
  for (ll j = 0; j < ll(n); ++j) {
    min_string += to_string(min_int[j]);
  }
  ll ans;
  ans = stoi(min_string);
  if (n == 1) {
    if (ans < 10) {
      MACRO_OUT(ans);
      ;
      return 0;
    }
  }
  if (n == 2) {
    if (ans >= 10 && ans < 100) {
      MACRO_OUT(ans);
      ;
      return 0;
    }
  }
  if (n == 3) {
    if (ans >= 100 && ans < 1000) {
      MACRO_OUT(ans);
      ;
      return 0;
    }
  }
  MACRO_OUT(-1);
  ;
  return 0;
}
