#include <bits/stdc++.h>
int main() {
  int N;
  int M;
  std::cin >> N >> M;
  if (M == 0) {
    if (N == 1) {
      std::cout << "0" << std::endl;
      return 0;
    } else {
      std::cout << "-1" << std::endl;
      return 0;
    }
  }
  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 (N == 1) {
    if (nums[0] == -1) {
      std::cout << "0" << std::endl;
    } else {
      std::cout << nums[0] << std::endl;
    }
  } else if (N == 2) {
    if (nums[0] == -1 || nums[0] == 0) {
      std::cout << "-1" << std::endl;
    } else {
      if (nums[1] == -1) {
        std::cout << nums[0] * 10 << std::endl;
      } else {
        std::cout << nums[0] * 10 + nums[1] << std::endl;
      }
    }
  } else {
    if (nums[0] == -1 || nums[0] == 0) {
      std::cout << "-1" << std::endl;
    } else {
      int value = 100 * nums[0];
      if (nums[1] != -1) {
        value += 10 * nums[1];
      }
      if (nums[2] != -1) {
        value += nums[2];
      }
      std::cout << value << std::endl;
    }
  }
  return 0;
}
