#include <bits/stdc++.h>
using namespace std;
inline namespace atcoder {
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
template <typename T, size_t Depth>
struct vector_helper {
  using type = vector<typename vector_helper<T, Depth - 1>::type>;
};
template <typename T>
struct vector_helper<T, 0> {
  using type = T;
};
template <typename T, size_t Depth>
using vector_t = typename vector_helper<T, Depth>::type;
template <typename T>
using vec = vector_t<T, 1>;
template <typename T>
using vvec = vector_t<T, 2>;
template <typename T>
using vvvec = vector_t<T, 3>;
}  // namespace atcoder
int main() {
  int n, m;
  cin >> n >> m;
  int expect[3] = {-1, -1, -1};
  while (m--) {
    int s, c;
    cin >> s >> c;
    --s;
    if (expect[s] != -1 && expect[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    expect[s] = c;
  }
  if (expect[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (auto &e : expect) e = max(e, 0);
  cout << (expect[0] * 100 + expect[1] * 10 + expect[2] * 1) << endl;
}
