#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> l(n, -1);
  for (int i = 0; i < m; i++) {
    int a, b;
    std::cin >> a >> b;
    if (l[a - 1] != -1 && l[a - 1] != b) {
      std::cout << -1 << std::endl;
      return 0;
    }
    if (n > 1 && a == 1 && b == 0) {
      std::cout << -1 << std::endl;
      return 0;
    }
    l[a - 1] = b;
  }
  for (int i = 0; i < n; i++) {
    int d = std::max(l[i], 0);
    std::cout << d;
  }
  std::cout << std::endl;
  return 0;
}
