#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N;
  std::cin >> M;
  std::string ans;
  if (M == 0) {
    if (N == 1) std::cout << 0 << std::endl;
    if (N == 2) std::cout << 10 << std::endl;
    if (N == 3) std::cout << 100 << std::endl;
    return 0;
  }
  for (int i = 0; i < N; ++i) {
    ans.push_back('-');
  }
  ans.push_back('\0');
  for (int i = 0; i < M; ++i) {
    int s, c;
    std::cin >> s;
    std::cin >> c;
    if (ans[s - 1] == '-' or ans[s - 1] - '0' == c) {
      ans[s - 1] = c + '0';
    } else {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  if (ans == "---") {
    std::cout << -1 << std::endl;
  } else {
    for (int i = 0; i < N; ++i) {
      if (ans[i] == '-') {
        ans[i] = '0';
      }
    }
    int num_ans = std::stoi(ans);
    if (N != 1) {
      int min = 1;
      for (int i = 0; i < N - 1; ++i) {
        min *= 10;
      }
      if (num_ans < min) {
        std::cout << -1 << std::endl;
        return 0;
      }
    }
    std::cout << num_ans << std::endl;
  }
  return 0;
}
