#include <bits/stdc++.h>
using namespace std;
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename C>
i64 SIZE(const C &c) {
  return static_cast<i64>(c.size());
}
template <typename T, size_t N>
i64 SIZE(const T (&)[N]) {
  return static_cast<i64>(N);
}
struct ProconInit {
  static constexpr int IOS_PREC = 15;
  static constexpr bool AUTOFLUSH = false;
  ProconInit() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(IOS_PREC);
    if (AUTOFLUSH) cout << unitbuf;
  }
} PROCON_INIT;
i64 N, M;
pair<i64, i64> C[5];
i64 x[3];
i64 digit(i64 n) {
  i64 cnt = 0;
  while (n) {
    n /= 10;
    cnt++;
  }
  return cnt;
}
void solve() {
  for (i64 i = (0), ixxxx_end = (3); i < ixxxx_end; ++i) x[i] = -1;
  for (i64 i = (0), ixxxx_end = (M); i < ixxxx_end; ++i) {
    pair<i64, i64> p = C[i];
    if (x[p.first] >= 0 && x[p.first] != p.second) {
      cout << -1 << endl;
      return;
    }
    if (p.first >= N) {
      cout << -1 << endl;
      return;
    }
    x[p.first] = p.second;
  }
  for (i64 i = (0), ixxxx_end = (3); i < ixxxx_end; ++i) {
    chmax(x[i], (i64)0);
  }
  i64 res = 0;
  for (i64 i = 0; i < N; i++) {
    res += x[N - i - 1] * pow(10, i);
  }
  if (digit(res) == N) {
    cout << res << endl;
  } else {
    cout << -1 << endl;
  }
}
int main() {
  cin >> N >> M;
  i64 s, c;
  for (i64 i = (0), ixxxx_end = (M); i < ixxxx_end; ++i) {
    cin >> s >> c;
    s--;
    C[i] = make_pair(s, c);
  }
  solve();
  return 0;
}
