#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> ans(n);
  for (auto &e : ans) e = -1;
  int dig;
  int val;
  bool illegal = false;
  int min = 100;
  for (int i = 0; i < m; i++) {
    std::cin >> dig >> val;
    if (ans[dig - 1] != -1 && ans[dig - 1] != val) {
      illegal = true;
      break;
    }
    if (val != 0) min = std::min(min, dig - 1);
    ans[dig - 1] = val;
  }
  for (int i = 0; i < min; i++) {
    if (ans[i] == 0) {
      illegal = true;
      break;
    }
  }
  if (illegal) {
    std::cout << -1 << "\n";
  } else {
    for (int i = 0; i < n; i++) {
      std::cout << ((ans[i] == -1) ? 0 : ans[i]);
    }
    std::cout << "\n";
  }
  return 0;
}
