#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  const int nmax = 4;
  std::array<int, nmax> arr;
  const int NIL = -1;
  arr.fill(NIL);
  int s, c;
  for (int i = 0; i < M; ++i) {
    std::cin >> s >> c;
    if (arr[s] == NIL) {
      arr[s] = c;
    } else if (arr[s] != c) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  for (int i = 1; i <= N; ++i) {
    if (arr[i] == NIL) {
      arr[i] = 0;
    }
  }
  if (arr[1] == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }
  int ans = 0;
  int keta = 1;
  for (int i = N; i >= 1; --i) {
    ans += arr[i] * keta;
    keta *= 10;
  }
  std::cout << ans << std::endl;
  return 0;
}
