#include <bits/stdc++.h>
struct GSB {
  long B;
  long C;
  GSB(long B2, long C2) {
    B = B2;
    C = C2;
  }
  bool operator<(const GSB& another) const { return B < another.B; }
};
int main() {
  long N, M;
  std::cin >> N >> M;
  std::vector<GSB> sc;
  for (long i = 0; i < M; i++) {
    long temp1, temp2;
    std::cin >> temp1 >> temp2;
    sc.push_back(GSB(temp1, temp2));
  }
  long R[3];
  for (long i = 0; i < 3; i++) {
    R[i] = -1;
  }
  bool flag = 0;
  for (long i = 0; i < M; i++) {
    if (R[sc[i].B - 1] == -1) {
      R[sc[i].B - 1] = sc[i].C;
    }
    if (R[sc[i].B - 1] != sc[i].C) {
      flag = 1;
      break;
    }
  }
  for (long i = 0; i < 3; i++) {
    if (R[i] == -1 && i != 0) {
      R[i] = 0;
    }
    if (R[i] == -1 && i == 0) {
      R[i] = 1;
    }
  }
  if (flag == 1) {
    std::cout << -1 << std::endl;
  } else if (M == 0) {
    std::cout << 0 << std::endl;
  } else if (R[0] == 0 && N != 1) {
    std::cout << -1 << std::endl;
  } else {
    for (long i = 0; i < N; i++) {
      std::cout << R[i];
    }
    std::cout << std::endl;
  }
  return 0;
}
