#include <bits/stdc++.h>
using ll = long long int;
const ll MOD = 1e9 + 7;
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];
    --s[i];
  }
  std::vector<int> ans(N, -1);
  for (int(i) = 0; i < (M); ++(i)) {
    if (ans[s[i]] > 0 && ans[s[i]] != c[i]) {
      std::cout << -1 << '\n';
      return 0;
    }
    ans[s[i]] = c[i];
  }
  if (N == 1) {
    std::cout << ans[0] << '\n';
    return 0;
  }
  if (ans[0] == 0) {
    std::cout << -1 << '\n';
    return 0;
  }
  if (ans[0] < 0) {
    ans[0] = 1;
  }
  for (int(i) = 0; i < (N); ++(i)) {
    std::cout << std::max(0, ans[i]);
  }
  std::cout << "" << '\n';
}
