#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];
  }
  bool failed = false;
  vector<int> str(N);
  for (int i = 0; i < N; i++) {
    str[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    if (S[i] <= N && str[S[i] - 1] == -1) {
      str[S[i] - 1] = C[i];
    } else if (S[i] <= N && str[S[i] - 1] == C[i]) {
      str[S[i] - 1] = C[i];
    } else {
      failed = true;
    }
  }
  int result = 0;
  for (int i = 0; i < N; i++) {
    if (str[i] == 0) {
      failed = true;
      break;
    }
    int a = 0;
    if (str[i] != -1) {
      a = str[i];
    }
    result += a * pow(10, N - i - 1);
  }
  if (failed) {
    cout << "-1" << endl;
  } else {
    cout << result << endl;
  }
}
