#include <bits/stdc++.h>
int main() {
  int N = 0;
  int M = 0;
  std::vector<int> Results;
  std::cin >> N >> M;
  Results.resize(N);
  for (int& result : Results) {
    result = -1;
  }
  for (int i = 0; i < M; ++i) {
    int s = 0, c = 0;
    std::cin >> s >> c;
    int& result = Results[s - 1];
    if (result >= 0) {
      if (result == c) continue;
      std::cout << -1 << std::endl;
      return 0;
    }
    result = c;
  }
  int answer = 0;
  for (int i = 0; i < static_cast<int>(Results.size()); ++i) {
    const int result = Results[Results.size() - i - 1];
    if (result < 0) continue;
    answer += result * std::pow(10.0, i);
  }
  std::cout << answer << std::endl;
  return 0;
}
