#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < M; i++) cin >> S[i] >> C[i];
  vector<int> ANS(N, -1);
  for (int i = 0; i < M; i++) {
    int digit = S[i] - 1;
    if (ANS[digit] != -1 && ANS[digit] != C[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      ANS[digit] = C[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (ANS[i] == -1) ANS[i] = 0;
  }
  if (N == 3 && ANS[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (N == 3 && ANS[0] == 0 && ANS[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (N == 2 && ANS[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans *= 10;
    ans += ANS[i];
  }
  cout << ans << endl;
}
