#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>> p(m);
  for (int i = 0; i < m; i++) {
    std::cin >> p[i].first >> p[i].second;
  }
  std::sort(p.begin(), p.end());
  std::vector<int> num(n, 0);
  for (int i = 0; i < p.size(); i++) {
    if (num[n - p[i].first] != 0 && num[n - p[i].first] != p[i].second) {
      std::cout << -1 << std::endl;
      return 0;
    }
    num[n - p[i].first] = p[i].second;
  }
  int temp = 0;
  for (int i = 0; i < n; i++) temp += num[i];
  if (temp == 0 && n != 1) {
    std::cout << -1 << std::endl;
    return 0;
  }
  for (int i = n - 1; i >= 0; i--) std::cout << num[i];
  std::cout << std::endl;
  return 0;
}
