#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  std::map<int, int> answer;
  for (int i = 0; i < N + 1; i++) {
    answer[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    int index, value = 0;
    std::cin >> index >> value;
    if (answer.find(index) != answer.end() && answer[index] != -1 &&
        answer[index] != value) {
      std::cout << -1;
      return 0;
    } else if (index > N) {
      std::cout << -1;
      return 0;
    }
    answer[index] = value;
  }
  if (answer[1] == 0) {
    std::cout << -1;
    return 0;
  } else if (answer[1] == -1) {
    answer[1] = 1;
  }
  int sum = 0;
  for (int i = 1; i < N + 1; i++) {
    if (answer[i] != -1) sum += answer[i] * std::pow(10, N - i);
  }
  std::cout << sum;
  return 0;
}
