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