#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  char 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;
  }
  int start = std::pow(10, n - 1);
  int end = std::pow(10, n) - 1;
  for (int i = start; i <= end; ++i) {
    auto str = std::to_string(i);
    bool ok = true;
    for (int j = 0; j <= n; ++j) {
      if (a[j] < 0) continue;
      if (std::to_string(a[j]) != str.substr(j - 1, 1)) ok = false;
    }
    if (ok) {
      std::cout << i << std::endl;
      return 0;
    }
  }
  std::cout << -1 << std::endl;
}
