#include <bits/stdc++.h>
int main() {
  int n, m, s, c, num;
  std::cin >> n >> m;
  int info[] = {0, 0, 0};
  for (int i = 0; i < m; i++) {
    std::cin >> s >> c;
    info[s - 1] = c;
  }
  bool flag = false;
  for (int j = 0; j < 1000; j++) {
    int tmp1 = j / 10;
    int tmp2 = tmp1 / 10;
    if (j % 10 == info[2] && tmp1 % 10 == info[1] && tmp2 % 10 == info[0]) {
      flag = true;
      num = 100 * info[0] + 10 * info[1] + info[2];
      break;
    }
  }
  switch (n) {
    case 1:
      if (num >= 0 && num < 10)
        flag = true;
      else
        flag = false;
      break;
    case 2:
      if (num >= 10 && num < 100)
        flag = true;
      else
        flag = false;
      break;
    case 3:
      if (num >= 100 && num < 1000)
        flag = true;
      else
        flag = false;
      break;
  }
  if (flag)
    std::cout << num << std::endl;
  else
    std::cout << "-1\n";
  return 0;
}
