#include <bits/stdc++.h>
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
std::vector<unsigned long long> genprimevec(const unsigned long long N);
long long extgcd(long long a, long long b, long long& x, long long& y);
long long nCr(long long n, long long r);
void stat();
template <typename T>
T fact(T num);
unsigned long long modpow(int x__, int n__, long long mod__);
template <typename T>
void debug(const T& t);
constexpr long long mod10_9p7 = 1000000000 + 7;
int main() {
  stat();
  int n, m;
  cin >> n >> m;
  std::vector<std::pair<int, int> > v(m);
  for (unsigned long long i = 0; i < (unsigned long long)(m); ++i) {
    cin >> v[i].first >> v[i].second;
  }
  string s;
  for (unsigned long long i = 0; i < (unsigned long long)(1000); ++i) {
    s = to_string(i);
    bool ok = true;
    for (auto x : v) {
      if (x.first > s.size()) {
        ok = false;
        break;
      }
      if (s[x.first - 1] != x.second) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
long long extgcd(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  long long d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
std::vector<unsigned long long> genprimevec(const unsigned long long N) {
  std::vector<bool> is_prime(N + 1);
  for (unsigned long long i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  std::vector<unsigned long long> P;
  for (unsigned long long i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (unsigned long long j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}
void stat() {}
long long nCr(long long n, long long r) {
  long long num = 1;
  for (long long i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}
template <typename T>
T fact(T num) {
  if (num == 1) {
    return 1;
  }
  return num * fact(num - 1);
}
unsigned long long modpow(int x__, int n__, long long mod__) {
  long long ret__ = 1;
  for (long long i__ = 0; i__ < n__; ++i__) {
    ret__ = ret__ * x__ % mod__;
  }
  return ret__;
}
template <typename T>
void debug(const T& t) {}
