#include <bits/stdc++.h>
using namespace std;
std::ostream& co_() { return std::cout << std::endl; }
std::istream& cn_() { return std::cin; }
template <class Head, class... Args>
std::ostream& co_(Head&& head, Args&&... args) {
  std::cout << head;
  return co_(std::forward<Args>(args)...);
}
template <class Head, class... Args>
std::istream& cn_(Head&& head, Args&&... args) {
  std::cin >> head;
  return cn_(std::forward<Args>(args)...);
}
int main() {
  int n, m;
  cn_(n, m);
  vector<int> ans(n, -1);
  for (long long(i) = 0; (i) < (m); ++(i)) {
    int s, c;
    cn_(s, c);
    if (ans[s - 1] >= 0 && ans[s - 1] != c) {
      co_("-1");
      return 0;
    }
    ans[s - 1] = c;
  }
  if (ans[0] == 0) {
    co_("-1");
    return 0;
  }
  for (auto& v : ans) {
    cout << max(v, 0);
  }
  cout << endl;
}
