#include <bits/stdc++.h>
int main() {
  int N, M, count = 0;
  std::cin >> N >> M;
  int digit = 0;
  std::vector<int> value(3);
  std::vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    std::cin >> s.at(i) >> c.at(i);
  }
  for (int i = 0; i < 1000; i++) {
    digit = log(i) / log(10) + 1;
    if (i == 0) {
      digit = 1;
    }
    {
      for (int j = 0; j < M; j++) {
        if ((int)(i / pow(10, N - s.at(j))) % 10 == c.at(j)) {
          count++;
        }
      }
      if (count == M) {
        std::cout << i << std::endl;
        return 0;
      } else {
        count = 0;
      }
    }
  }
  std::cout << -1 << std::endl;
  return 0;
}
