#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> val(n, -1);
  std::vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    std::cin >> s[i] >> c[i];
    s[i]--;
    if (val[s[i]] == -1) {
      val[s[i]] = c[i];
    } else if (val[s[i]] != c[i]) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  if (val[0] == 0 && n == 1) {
    std::cout << 0 << std::endl;
  } else if (val[0] == 0) {
    std::cout << -1 << std::endl;
  } else {
    int ans = 0;
    int base = 1;
    for (int i = 0; i < n; i++) {
      if (val[n - 1 - i] != -1) {
        ans += base * val[n - 1 - i];
      }
      base *= 10;
    }
    if (val[0] == -1) {
      ans += base / 10;
    }
    std::cout << ans << std::endl;
  }
  return 0;
}
