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