#include <bits/stdc++.h>
using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;
template <typename T>
constexpr T inf =
    static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) +
    7;
constexpr llong mod = 1e9 + 7;
int main() {
  llong N, M;
  vector<llong> n(4, -1);
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    llong s, c;
    cin >> s >> c;
    if (n[s] == -1) {
      n[s] = c;
    } else if (n[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  llong ans = 0;
  if (N > 1 && n[1] == 0) {
    ans = -1;
  } else {
    ans = pow(10, N - 1) * max(1ll, n[1]);
    for (int i = 2; i <= N; ++i) {
      ans += pow(10, N - i) * max(0ll, n[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
