#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  vector<P> p(M);
  for (int i = 0; i < M; i++) cin >> p[i].first >> p[i].second;
  vector<int> A(N, -1);
  for (int i = 0; i < M; i++) {
    if (A[p[i].first - 1] != -1 && A[p[i].first - 1] != p[i].second) {
      cout << -1 << endl;
      return 0;
    }
    A[p[i].first - 1] = p[i].second;
  }
  if ((N == 2 && A[0] == 0) || (N == 3 && A[0] == 0)) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == -1) A[i] = 0;
    cout << A[i];
  }
  cout << endl;
  return 0;
}
