#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);
  }
  int loop_start;
  int loop_end;
  if (N == 1) {
    loop_start = 0;
    loop_end = 10;
  } else if (N == 2) {
    loop_start = 10;
    loop_end = 100;
  } else if (N == 3) {
    loop_start = 100;
    loop_end = 1000;
  }
  bool flag = false;
  int result = 1000;
  for (int i = loop_start; i < loop_end; i++) {
    string strwk = to_string(i);
    for (int j = 0; j < M; j++) {
      if (strwk.at(S.at(j)) == C.at(j)) {
        if (j == M - 1) {
          flag = true;
          result = min(result, i);
        }
      } else
        break;
    }
  }
  if (M == 0) {
    if (N == 1)
      cout << 0 << endl;
    else if (N == 2)
      cout << 10 << endl;
    else if (N == 3)
      cout << 100 << endl;
  } else if (flag)
    cout << result << endl;
  else
    cout << -1 << endl;
  return 0;
}
