#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, m;
  std::cin >> n >> m;
  std::vector<std::pair<int, int>> cond;
  std::vector<int> ans(n, 0);
  for (int i = 0; i < m; i++) {
    int s, c;
    std::cin >> s >> c;
    cond.push_back(std::make_pair(s, c));
  }
  bool written[n];
  bool flag = true;
  for (int i = 0; i < cond.size(); i++) {
    if (cond[i].first - 1 > n) {
      flag = false;
    }
    if (!written[cond[i].first - 1]) {
      ans[cond[i].first - 1] = cond[i].second;
      written[cond[i].first - 1] = true;
    } else if (written[cond[i].first - 1] &&
               ans[cond[i].first - 1] != cond[i].second) {
      flag = false;
    }
  }
  if (ans[n - 1] == 0) flag = false;
  if (!flag) {
    std::cout << -1 << std::endl;
    return 0;
  } else {
    for (int i = 0; i < n; i++) std::cout << ans[i];
    std::cout << std::endl;
  }
  return 0;
}
