#include <bits/stdc++.h>
int main() {
  int N, M;
  int s[10];
  int c[10];
  int num[10] = {-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];
  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 != 1 && num[0] == 0) exist = false;
  int g_num = 0;
  if (exist) {
    for (int i = 0; i < N; ++i) {
      if (num[i] == -1)
        g_num += 0;
      else
        g_num += (std::pow(10, (N - i - 1)) * num[i]);
    }
    std::cout << g_num << std::endl;
  } else {
    std::cout << -1 << std::endl;
  }
  return 0;
}
