#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> memos(N, false);
  std::vector<int> digits(N, 0);
  for (int i = 0; i < M; ++i) {
    int s, c;
    std::cin >> s >> c;
    if (memos[s - 1] && (digits[s - 1] != c)) {
      std::cout << "-1" << std::endl;
      return 0;
    }
    digits[s - 1] = c;
    memos[s - 1] = true;
  }
  if ((1 < N) && (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;
}
