#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  string C = "";
  for (int i = 0; i < M; i++) {
    cin >> S.at(i);
    char ci;
    cin >> ci;
    C += ci;
  }
  int max = 1;
  for (int i = 1; i <= N; i++) {
    max *= 10;
  }
  int guess = -1;
  for (int i = max / 10; i < max; i++) {
    for (int j = 0; j < M; j++) {
      string num = to_string(i);
      if (num.size() < S.at(j)) {
        break;
      } else if (num.at(S.at(j) - 1) != C.at(j)) {
        break;
      } else if (j == M - 1) {
        if (guess == -1) {
          guess = i;
        }
      }
    }
  }
  cout << guess;
}
