#include <bits/stdc++.h>
template <typename T>
T powint(const T& x, const T& y) {
  T ret = 1;
  for (int i = 0; i < y; ++i) ret *= x;
  return ret;
}
int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> s(M), c(M);
  for (int i = 0; i < M; ++i) std::cin >> s[i] >> c[i];
  for (int i = 0; i < M; ++i) {
    if (c[i] == 0 && N == 4 - s[i]) {
      std::cout << "-1" << std::endl;
      return 0;
    }
  }
  for (int i = 0; i < M; ++i) {
    for (int j = i + 1; j < M; ++j) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          std::cout << "-1" << std::endl;
          return 0;
        }
      }
    }
  }
  std::vector<int> ans(N, 0);
  for (int i = 0; i < M; ++i) {
    ans[s[i] - 1] = c[i];
  }
  for (int i = 0; i < N; ++i) {
    std::cout << ans[i];
  }
  std::cout << std::endl;
  return 0;
}
