#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  int data[2][M];
  for (int i = 0; i < M; ++i) {
    std::cin >> data[0][i] >> data[1][i];
  }
  int an[3];
  for (int i = 0; i < 3; ++i) an[i] = 0;
  for (int i = 0; i < M; ++i) {
    an[data[0][i] - 1] = data[1][i];
  }
  if (an[0] == 0)
    std::cout << "-1" << std::endl;
  else
    std::cout << an[0] * 100 + an[1] * 10 + an[2] << std::endl;
  return 0;
}
