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