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