#include <bits/stdc++.h>
long double func(long double& i, long double& P) {
  long double t = 0;
  while (i < P) {
    i *= 2;
    ++t;
  }
  return t;
}
int main() {
  long long N, M;
  std::cin >> N >> M;
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; ++i) {
    std::cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  for (int i = 0; i < N; ++i) {
    if (s[i] > M) {
      std::cout << -1 << std::endl;
      return 0;
    }
    for (int j = 0; j < N; ++j) {
      if (s[i] == s[j] && c[i] != c[j]) {
        std::cout << -1 << std::endl;
        return 0;
      }
    }
  }
  long long ans = 0;
  bool m1 = false;
  bool m2 = false;
  bool m3 = false;
  int p1 = 0;
  int p2 = 0;
  int p3 = 0;
  for (int i = 0; i < M; ++i) {
    if (s[i] == 1) {
      m3 = true;
      p3 = i;
    }
    if (s[i] == 2) {
      m2 = true;
      p2 = i;
    }
    if (s[i] == 3) {
      m1 = true;
      p1 = i;
    }
  }
  if (m3 == true) ans += c[p3] * std::pow(10, N - 1);
  if (m2 == true) ans += c[p2] * std::pow(10, N - 2);
  if (m1 == true) ans += c[p1] * std::pow(10, N - 3);
  if (N == 3 && ans < 100) ans += 100;
  if (N == 2 && ans < 10) ans += 10;
  std::cout << ans << std::endl;
}
