#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = int64_t;
using pii = pair<int64_t, int64_t>;
using pis = pair<int64_t, str>;
using psi = pair<str, int64_t>;
using vi = vector<int64_t>;
using vvi = vector<vector<int64_t>>;
using vs = vector<str>;
using vpii = vector<pair<int64_t, int64_t>>;
constexpr ll MOD = 1000000007;
constexpr int INFI = int(0x3f000000);
constexpr ll INF = ll(0x3f0000003f000000);
constexpr double EPS = 1e-9;
constexpr int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
              dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
inline bool in(string s, string c) { return (s.find(c) != string::npos); }
inline bool in(string s, char c) { return (s.find(c) != string::npos); }
template <class T>
T udiv(T a, T b) {
  return (a + b - 1) / b;
}
template <class T>
T rdiv(T a, T b) {
  return (a + b / 2) / b;
}
void print_args(ostream&) {}
template <class S, class... T>
void print_args(ostream& out, const S& a, const T&... args) {
  out << ' ' << a;
  print_args(out, args...);
}
template <class S, class... T>
void print(const S& a, const T&... args) {
  std::cout << a;
  print_args(std::cout, args...);
  std::cout << '\n';
}
template <class S, class... T>
void debug_args(const S& a, const T&... args) {
  std::cout << "(L:" << std::setw(3) << a << ")";
  print_args(std::cout, args...);
  std::cout << '\n';
}
struct setup_main {
  setup_main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(0);
    std::cout << fixed << setprecision(15);
  }
} setup_main_;
ll ans(-1);
struct pbi {
  bool b;
  ll k;
  pbi(bool bb, ll kk) { b = bb, k = kk; }
};
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  using vpbi = vector<pbi>;
  vpbi list(4, pbi(false, 0));
  for (int i = (0), i_len = (M); i < i_len; ++i) {
    if (list[s[i]].b == false) {
      list[s[i]].b = true, list[s[i]].k = c[i];
    } else {
      if (list[s[i]].k != c[i])
        return;
      else
        list[s[i]].b = true, list[s[i]].k = c[i];
    }
  }
  if (list[1].b = true and list[1].k == 0) return;
  ans = list[1].k * 100 + list[2].k * 10 + list[3].k;
  ans = max(ll(pow(10, N - 1)), ans);
}
signed main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  print(ans);
  return 0;
}
