#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  map<long long, long long> mp;
  for (long long i = 0; i < M; ++i) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (mp.find(s) == mp.end()) {
      mp[s] = c;
    } else if (mp[s] != c) {
      printf("-1\n");
      return 0;
    }
  }
  if (mp.find(0) == mp.end()) {
    mp[0] = 1;
  } else if (mp[0] == 0) {
    if (N == 1) {
      printf("0\n");
      return 0;
    } else {
      printf("-1\n");
      return 0;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < N; ++i) {
    ans *= 10;
    ans += mp[i];
  }
  printf("%lld\n", ans);
  return 0;
}
