#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
const int MOD = 1e9 + 7;
const long long INF = 1e+14;
const double PI = 3.14159265349;
template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& input) {
  os << "[ ";
  for (long long(i) = 0; (i) < (input.size()); (i)++) {
    os << input[i];
    if (i < input.size() - 1) {
      os << " ";
    }
  }
  os << " ]";
  return os;
}
void print() { std::cout << "\n"; }
template <class T, class... A>
void print(const T& first, const A&... rest) {
  std::cout << first << " ";
  print(rest...);
}
template <class... A>
void print(const A&... rest) {
  print(rest...);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M), c(M);
  for (long long(i) = 0; (i) < (M); (i)++) {
    cin >> s[i] >> c[i];
  }
  vector<long long> ansv(N, -1);
  for (long long(i) = 0; (i) < (M); (i)++) {
    long long d = N - s[i];
    if (ansv[d] != -1 && ansv[d] != c[i]) {
      cout << -1 << "\n";
      return 0;
    }
    ansv[d] = c[i];
  }
  if (ansv[N - 1] == 0) {
    cout << -1 << "\n";
    return 0;
  } else if (ansv[N - 1] == -1) {
    ansv[N - 1] = 1;
  }
  long long ans = 0;
  for (long long i = N - 1; i >= 0; i--) {
    ans *= 10;
    if (ansv[i] > -1) {
      ans += ansv[i];
    }
  }
  cout << ans << "\n";
  return 0;
}
