#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int64_t> >;
using WeightedGraph = vector<vector<pair<int64_t, int64_t> > >;
const int64_t INF = 2000000000ll;
const long double PI = acosl(-1);
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int64_t power(int64_t a, int64_t b) {
  return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;
}
int64_t perm(int64_t N, int64_t K) {
  int64_t x = 1;
  for (int64_t i = 1; i <= K; i++) {
    x = x * (N - i + 1);
  }
  return x;
}
int64_t factorial(int64_t N) { return perm(N, N); }
int64_t comb(int64_t N, int64_t K) {
  return factorial(N) / factorial(K) / factorial(N - K);
}
int64_t hcomb(int64_t N, int64_t K) { return comb(N + K - 1, N - 1); }
int64_t dtoi(double d) { return round(d); }
int64_t isprime(int64_t n) {
  if (n < 2) return 0;
  for (int64_t i = 2; i * i <= n; ++i) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int64_t mystoi(string S) {
  int64_t num = 0;
  for (int64_t i = (int64_t)S.length() - 1; i >= 0; i--) {
    num += (S[i] - '0') * power(10, S.length() - 1 - i);
  }
  return num;
}
template <class T>
int64_t SUM(T a) {
  int64_t sum = 0;
  for (auto iter : a) sum += iter;
  return sum;
}
void solve(int64_t N, int64_t M, const vector<int64_t>& s,
           const vector<int64_t>& c);
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> s(M), c(M);
  for (int64_t i = 0; (i) < (int64_t)(M); ++(i)) {
    cin >> s[i] >> c[i];
  }
  solve(N, M, s, c);
  return 0;
}
void solve(int64_t N, int64_t M, const vector<int64_t>& s,
           const vector<int64_t>& c) {
  int64_t ans = -1;
  if (N == 1) {
    for (int64_t i = 0; (i) < (int64_t)(10); ++(i)) {
      int64_t ch = 1;
      for (int64_t j = 0; (j) < (int64_t)(M); ++(j)) {
        if (i != c[0]) ch = 0;
      }
      if (ch) {
        ans = i;
        break;
      }
    }
  }
  if (N == 2) {
    for (int64_t i = 10; i < 100; i++) {
      int64_t ch = 1;
      for (int64_t j = 0; (j) < (int64_t)(M); ++(j)) {
        if (s[j] == 1)
          if (i / 10 != c[j]) ch = 0;
        if (s[j] == 2)
          if (i % 10 != c[j]) ch = 0;
      }
      if (ch) {
        ans = i;
        break;
      }
    }
  }
  if (N == 3) {
    for (int64_t i = 100; i < 1000; i++) {
      int64_t ch = 1;
      for (int64_t j = 0; (j) < (int64_t)(M); ++(j)) {
        if (s[j] == 1)
          if (i / 100 != c[j]) ch = 0;
        if (s[j] == 2)
          if (i % 100 / 10 != c[j]) ch = 0;
        if (s[j] == 3)
          if (i % 10 != c[j]) ch = 0;
      }
      if (ch) {
        ans = i;
        break;
      }
    }
  }
  cout << ans << "\n";
}
