#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; }
};
int solve(long long N, long long M, std::vector<long long> s,
          std::vector<long long> c) {
  if (N == 1) {
    sort(begin(c), end(c));
    c.erase(unique(begin(c), end(c)), c.end());
    if (c.size() > 1)
      return -1;
    else
      return c[0];
  }
  for (int i = (0), i_len = (M); i < i_len; ++i)
    if (s[i] == 1 and c[i] == 0) return -1;
  array<int, 4> i = {0, 0, 0, 0};
  if (N == 2) {
    for (i[1] = 1; i[1] < 10; i[1]++) {
      for (i[2] = 0; i[2] < 10; i[2]++) {
        ll ii = i[1] * 10 + i[2];
        for (int j = (0), j_len = (M); j < j_len; ++j) {
          if (i[s[j]] != c[j]) ii = 0;
        }
        if (ii != 0) return ii;
      }
    }
  }
  if (N == 3) {
    for (i[1] = 1; i[1] < 10; i[1]++) {
      for (i[2] = 0; i[2] < 10; i[2]++) {
        for (i[3] = 0; i[3] < 10; i[3]++) {
          ll ii = i[1] * 100 + i[2] * 10 + i[3];
          for (int j = (0), j_len = (M); j < j_len; ++j) {
            if (i[s[j]] != c[j]) ii = 0;
          }
          if (ii != 0) return ii;
        }
      }
    }
  }
  return (-1);
}
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]);
  }
  print(solve(N, M, std::move(s), std::move(c)));
  return 0;
}
