#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  long long N, M, ans, cnt;
  cin >> N >> M;
  vector<long long> K(N);
  for (long long i = 0; i < (long long)(M); i++) {
    long long s, c;
    cin >> s >> c;
    if (K[s - 1] == 0) {
      K[s - 1] = c;
    } else if (K[s - 1] == c)
      continue;
    else
      ans = -1;
  }
  for (long long i = 0; i < (long long)(N); i++) {
    cnt += K[i];
  }
  if (cnt == 0) {
    cout << -1;
  } else {
    for (long long i = 0; i < N; i++) {
      if (K[N - 1] == 0) {
        K[N - 1] = 1;
      } else
        cout << K[i];
    }
  }
}
