#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  vector<char> C(M);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
  }
  bool flag = false;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if ((S.at(i) == S.at(j)) && (C.at(i) != C.at(j))) flag = true;
    }
  }
  vector<char> number(N, '0');
  for (int i = 0; i < M; i++) {
    number.at(S.at(i) - 1) = C.at(i);
  }
  if (M == 0) {
    if (N == 1)
      cout << 0;
    else if (N == 2)
      cout << 10;
    else if (N == 3)
      cout << 100;
  } else if ((N == 3 && number.at(0) == '0') ||
             (N == 2 && number.at(0) == '0') || flag) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < N; i++) {
      cout << number.at(i);
    }
  }
  return 0;
}
