#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans(-1);
  size_t N, M;
  cin >> N >> M;
  int S[3] = {(10), (10), (10)};
  for (size_t i = 0; i < M; ++i) {
    int si, ci;
    cin >> si >> ci;
    if (S[si - 1] != (10) && S[si - 1] != ci) {
      cout << "-1" << endl;
      return 0;
    }
    S[si - 1] = ci;
  }
  if ((S[0] == (10) || S[0] == 0) && N > 1) {
    cout << "-1" << endl;
    return 0;
  }
  if (S[0] == (10)) {
    cout << "0" << endl;
    return 0;
  }
  for (size_t i = 0; i < N; ++i) {
    if (S[i] == (10)) S[i] = 0;
  }
  switch (N) {
    case (3):
      ans = S[0] * 100 + S[1] * 10 + S[2];
      break;
    case (2):
      ans = S[0] * 10 + S[1];
      break;
    case (1):
      ans = S[0];
      break;
    default:
      break;
  }
  cout << ans << endl;
  return 0;
}
