#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template <typename Type>
inline void chmin(Type& a, Type b) {
  if (a > b) a = b;
}
template <typename Type>
inline void chmax(Type& a, Type b) {
  if (a < b) a = b;
}
template <typename Arr, typename Type>
inline void fill(Arr& arr, Type v) {
  std::fill(arr.begin(), arr.end(), v);
}
template <typename Type>
inline void sort(Type& arr) {
  std::sort(arr.begin(), arr.end());
}
template <typename Type>
inline Type nth(vector<Type>& arr, size_t pos) {
  std::nth_element(arr.begin(), arr.begin() + pos, arr.end());
  return arr[pos];
}
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  vector<ll> S(M);
  vector<ll> C(M);
  for (ll i = 0; i < (M); ++i) {
    cin >> S[i] >> C[i];
  }
  for (ll i = 0; i < (999); ++i) {
    ll is[3] = {
        i > 100 ? (i / 100) % 10 : -1,
        i > 10 ? (i / 10) % 10 : -1,
        i % 10,
    };
    bool valid = true;
    for (ll j = 0; j < (M); ++j) {
      valid &= is[S[j] - 1] == C[j];
    }
    if (valid) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
