#include <bits/stdc++.h>
int main() {
  int N;
  int M;
  int s[10];
  int c[10];
  int num[10];
  for (int i = 0; i < 10; ++i) num[i] = -1;
  std::cin >> N >> M;
  for (int i = 0; i < M; i++)
    for (int j = 0; j < 2; j++)
      if (j == 0)
        std::cin >> s[i];
      else
        std::cin >> c[i];
  if (M == 0) {
    if (N >= 2)
      std::cout << std::pow(10, N - 1) << std::endl;
    else
      std::cout << 0 << std::endl;
    return 0;
  }
  bool exist = true;
  for (int i = 0; i < M; ++i) {
    if (num[s[i] - 1] == -1) {
      num[s[i] - 1] = c[i];
    } else if (num[s[i] - 1] != c[i]) {
      exist = false;
      break;
    }
    if (N >= 2 && num[0] == 0) {
      exist = false;
      break;
    }
  }
  if (!exist) {
    std::cout << -1 << std::endl;
    return 0;
  } else {
    for (int i = 0; i < N; ++i) num[i] = (num[i] == -1 ? 0 : num[i]);
  }
  int g_num = 0;
  for (int i = 0; i < N; ++i) g_num += (std::pow(10, N - i - 1) * num[i]);
  std::cout << g_num << std::endl;
  return 0;
}
