#include <bits/stdc++.h>
int resolve(int digits, const std::list<std::pair<int, int> >& constraints) {
  std::vector<int> vals(digits, 0);
  std::vector<int> binded(digits, 0);
  for (const auto& p : constraints) {
    if (p.first == 1 && p.second == 0 && digits == 1) {
      return 0;
    } else if (p.first == 1 && p.second == 0) {
      return -1;
    } else if (!binded[p.first - 1]) {
      binded[p.first - 1] = 1;
      vals[p.first - 1] = p.second;
    } else if (vals[p.first - 1] == p.second) {
      continue;
    } else {
      return -1;
    }
  }
  if (!vals[0]) {
    vals[0] = 1;
  }
  int res = 0;
  for (int i = digits, j = 0; i > 0; --i, ++j) {
    res += vals[j] * pow(10, i - 1);
  }
  return res;
}
int main(int argc, char const* argv[]) {
  std::string str;
  getline(std::cin, str, ' ');
  int n = std::stoi(str);
  getline(std::cin, str);
  int m = std::stoi(str);
  std::list<std::pair<int, int> > sc_list;
  std::string line;
  std::string elem;
  while (getline(std::cin, line)) {
    std::stringstream ss(line);
    int s, c;
    getline(ss, elem, ' ');
    s = std::stoi(elem);
    getline(ss, elem);
    c = std::stoi(elem);
    sc_list.push_back({s, c});
  }
  std::cout << resolve(n, sc_list) << std::endl;
  return 0;
}
