#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  int num[3] = {0, 0, 0};
  int count[3] = {0, 0, 0};
  int s, c;
  for (int i = 0; i < m; i++) {
    std::cin >> s >> c;
    num[s - 1] = c;
    count[s - 1]++;
  }
  bool ans = true;
  for (int i = 0; i < 3; i++) {
    if (count[i] > 1) {
      ans = false;
    }
  }
  if (ans && num[3 - n] != 0) {
    for (int i = 0; i < m; i++) {
      std::cout << num[i];
    }
    std::cout << std::endl;
  } else {
    std::cout << -1 << std::endl;
  }
  return 0;
}
