#include <bits/stdc++.h>
int const MAXN = 3;
int digit[MAXN + 1], N, M;
int main() {
  std::cin >> N >> M;
  std::fill_n(digit, N + 1, -1);
  for (int i = 0; i < M; ++i) {
    int s, c;
    std::cin >> s >> c;
    if (s == 1 && c == 0 && N > 1) {
      std::cout << "-1" << std::endl;
      return 0;
    }
    if (digit[s] == -1)
      digit[s] = c;
    else if (digit[s] != c) {
      std::cout << "-1" << std::endl;
      return 0;
    }
  }
  if (digit[1] < 0) digit[1] = 1;
  for (int i = 2; i <= N; ++i)
    if (digit[i] < 0) digit[i] = 0;
  int ans = digit[1];
  for (int i = 2; i <= N; ++i) ans = ans * 10 + digit[i];
  std::cout << ans << std::endl;
  return 0;
}
