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