#include <bits/stdc++.h>
using namespace std;
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  map<long long, long long> tab;
  long long acc = 0;
  for (long long i = 0; i < M; i++) {
    if (N != 1 && s[i] == 1 && c[i] == 0) goto err;
    if (tab.count(s[i]) > 0) {
      if (tab[s[i]] != c[i]) goto err;
      continue;
    }
    acc += (c[i] * pow(10, N - s[i]));
    tab[s[i]] = c[i];
  }
  if (acc == 0) {
    cout << 0 << endl;
  } else {
    cout << ((acc < pow(10, N - 1)) ? (acc + pow(10, N - 1)) : acc) << endl;
  }
  return;
err:
  cout << -1 << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
