#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
const long long INF =
    sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const long long MOD = (long long)1e9 + 7;
const double EPS = 1e-9;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  map<long long, long long> dmap;
  long long N, M;
  cin >> N >> M;
  long long s, c;
  bool ok = true;
  for (long long i = (0), i_len = (M); i < i_len; i++) {
    cin >> s >> c;
    s = N - s + 1;
    if (dmap.find(s) != dmap.end() && dmap[s] != c || s == N && c == 0)
      ok = false;
    dmap[s] = c;
  }
  if (N != 1 && dmap[N] == 0) dmap[N] = 1;
  if (ok) {
    long long ans = 0;
    for (auto p : dmap) {
      long long d = p.second;
      for (long long i = (0), i_len = (p.first - 1); i < i_len; i++) {
        d *= 10;
      }
      ans += d;
    }
    cout << ans << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
