#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> s(M);
  std::vector<char> c(M);
  for (int i = 0; i < M; i++) {
    std::cin >> s[i] >> c[i];
  }
  int begin = 1;
  int end = 10;
  for (int i = 1; i < N; i++) {
    begin *= 10;
    end *= 10;
  }
  int ans = -1;
  for (int i = begin; i < end; i++) {
    bool F = true;
    std::string num_str = std::to_string(i);
    for (int j = 0; j < M; j++) {
      if (num_str[s[j]] == c[j]) {
        F = false;
        break;
      }
    }
    if (F) {
      ans = i;
      break;
    }
  }
  std::cout << ans << std::endl;
}
