#include <bits/stdc++.h>
using namespace std;
template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}
template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}
bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}
uint64_t dec_dig(uint64_t num) {
  uint64_t res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}
uint64_t gcd(uint64_t a, uint64_t b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? gcd(b, a % b) : a;
}
int main() {
  cout << setprecision(15);
  uint32_t N, M;
  cin >> N >> M;
  vector<uint32_t> s(M), c(M);
  for (uint32_t i = 0; i < M; ++i) cin >> s[i] >> c[i];
  uint32_t Mlim = 1;
  for (uint32_t i = 0; i < N; ++i) Mlim *= 10;
  uint32_t res = Mlim;
  for (uint32_t i = Mlim / 10; i < Mlim; ++i) {
    bool flag = true;
    for (uint32_t j = 0; j < M; ++j) {
      uint32_t tmp = Mlim;
      for (uint32_t k = 0; k < s[j]; ++k) tmp /= 10;
      if (((i / tmp) % (10)) != c[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      res = i;
      break;
    }
  }
  if (res != Mlim)
    cout << res << endl;
  else
    cout << -1 << endl;
  return 0;
}
