#include <bits/stdc++.h>
int main() {
  int N;
  int M;
  std::cin >> N >> M;
  std::vector<int> nums;
  for (int i = 0; i < N; ++i) {
    nums.push_back(-1);
  }
  for (int i = 0; i < M; ++i) {
    int s;
    int c;
    std::cin >> s >> c;
    if (nums[s - 1] < 0 || nums[s - 1] == c) {
      nums[s - 1] = c;
    } else {
      std::cout << "-1" << std::endl;
      return 0;
    }
  }
  if (nums[0] == -1) {
    if (N == 1) {
      std::cout << "0" << std::endl;
    } else {
      std::cout << "-1" << std::endl;
    }
  } else {
    for (int i = 0; i < N; ++i) {
      if (nums[i] == -1) {
        nums[i] = 0;
      }
    }
    if (N == 1) {
      std::cout << nums[0] << std::endl;
    } else if (N == 2) {
      std::cout << nums[0] * 10 + nums[1] << std::endl;
    } else if (N == 3) {
      std::cout << nums[0] * 100 + nums[1] * 10 + nums[2] << std::endl;
    }
  }
  return 0;
}
