#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  if (N == 1 && M == 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
    if (S.at(i) == 1 && C.at(i) == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (M > 1) {
    for (int i = 0; i < M; i++) {
      for (int j = i + 1; j < M; j++) {
        if (S.at(i) == S.at(j)) {
          if (C.at(i) != C.at(j)) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
  }
  vector<int> A(N);
  for (int i = 0; i < M; i++) {
    int tmp = S.at(i);
    A.at(tmp - 1) = C.at(i);
  }
  if (A.at(0) == 0) {
    A.at(0) = 1;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += pow(10, N - i - 1) * A.at(i);
  }
  cout << ans << endl;
}
