#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::pair<int, int>> p(n);
  for (int i = 0; i < m; ++i) std::cin >> p.at(i).first >> p.at(i).second;
  for (int i = 0; i < 1000; ++i) {
    int xi = i;
    std::vector<int> x;
    do {
      x.push_back(xi % 10);
      xi /= 10;
    } while (xi > 0);
    if ((int)x.size() != n) continue;
    std::reverse(x.begin(), x.end());
    bool ok = true;
    for (auto &pi : p) {
      if (x[pi.first - 1] != pi.second) ok = false;
    }
    if (!ok) continue;
    for (auto &v : x) std::cout << v;
    std::cout << std::endl;
    return 0;
  }
  std::cout << -1 << std::endl;
}
