#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> a(n);
  std::fill(a.begin(), a.end(), -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    std::cin >> s >> c;
    if (a[s - 1] == -1)
      a[s - 1] = c;
    else if (a[s - 1] != c) {
      std::cout << "-1\n";
      return 0;
    }
  }
  if (a.size() == 1) {
    std::cout << 0;
    return 0;
  }
  if (a[0] == -1 || a[0] == 0) {
    std::cout << "-1\n";
    return 0;
  }
  for (auto&& v : a) {
    if (v == -1) v = 0;
    std::cout << v;
  }
}
