#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> ans(N, -1);
  string A = "";
  for (long long i = 0; i < M; i++) {
    long long s, c;
    cin >> s >> c;
    if (ans[s - 1] == -1) ans[s - 1] = c;
    if (ans[s - 1] != -1 && ans[s - 1] != c) {
      A += "-1";
      break;
    }
    if (s == 1 && c == 0) {
      A += "-1";
      break;
    }
  }
  if (A.size() == 0) {
    for (long long i = 0; i < N; i++) {
      if (i == 0 && ans[i] == -1) ans[i] = 1;
      if (i != 0 && ans[i] == -1) ans[i] = 0;
      A += to_string(ans[i]);
    }
  }
  cout << A << endl;
}
