#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  int s[M], c[M];
  bool N_flag = false;
  for (int i = 0; i < M; ++i) {
    std::cin >> s[i] >> c[i];
    s[i] = N - s[i] + 1;
    if (s[i] == N) N_flag = true;
  }
  int ans = 0;
  bool flag[N];
  std::fill(flag, flag + N, false);
  for (int i = 0; i < M; ++i) {
    if (flag[s[i] - 1]) continue;
    for (int j = i + 1; j < M; ++j) {
      if (s[i] == s[j] && c[i] != c[j]) {
        std::cout << -1 << std::endl;
        return 0;
      }
    }
    if (s[i] == N && c[i] == 0) {
      std::cout << -1 << std::endl;
      return 0;
    }
    ans += c[i] * std::pow(10, s[i] - 1);
    flag[s[i] - 1] = true;
  }
  if (!N_flag) ans += std::pow(10, N - 1);
  std::cout << ans << std::endl;
  return 0;
}
