#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> vals(n, -1);
  for (int i = 0; i < m; ++i) {
    int sp1, c;
    std::cin >> sp1 >> c;
    int s = sp1 - 1;
    if (i == 0 && c == 0) {
      std::cout << -1 << std::endl;
      return 0;
    }
    if (vals[s] != -1 && vals[s] != c) {
      std::cout << -1 << std::endl;
      return 0;
    }
    vals[s] = c;
  }
  int ret = 0, i = 0;
  for (int val : vals) {
    if (val == -1) {
      val = 0;
    }
    if (i == 0 && n > 1 && val == 0) {
      std::cout << -1 << std::endl;
      return 0;
    }
    ret *= 10;
    ret += val;
    ++i;
  }
  std::cout << ret << std::endl;
  return 0;
}
