#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> s(M);
  std::vector<int> c(M);
  for (int i = 0; i < M; ++i) {
    std::cin >> s[i] >> c[i];
  }
  bool invalid = false;
  std::vector<int> value(N, -1);
  for (int i = 0; i < M; ++i) {
    if (value[s[i] - 1] != -1) {
      if (value[s[i] - 1] != c[i]) {
        invalid = true;
        break;
      }
    }
    value[s[i] - 1] = c[i];
  }
  for (int i = 0; i < N; ++i) {
    if (value[i] == -1) {
      value[i] = 0;
    }
  }
  if (N != 1 && value[0] == 0) {
    invalid = true;
  }
  if (invalid) {
    std::cout << "-1\n";
  } else {
    for (int i = 0; i < N; ++i) {
      std::cout << value[i];
    }
    std::cout << '\n';
  }
  return 0;
}
