#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] != -1 && a[s] != c) {
      std::cout << -1 << std::endl;
      return 0;
    }
    a[s] = c;
  }
  if (a[1] == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] > 0)
      std::cout << a[i];
    else
      std::cout << 0;
  }
  std::cout << std::endl;
}
