#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  int s[M];
  int c[M];
  for (int i = 0; i < M; ++i) {
    std::cin >> s[i] >> c[i];
  }
  int max, min;
  if (N == 1) {
    min = 1;
    max = 9;
  } else if (N == 2) {
    min = 10;
    max = 99;
  } else {
    min = 100;
    max = 999;
  }
  for (int i = min; i <= max; ++i) {
    const std::string str = std::to_string(i);
    bool ok = true;
    for (int j = 0; j < M; ++j) {
      if (str[s[j] - 1] != ('0' + c[j])) {
        ok = false;
        break;
      }
    }
    if (ok) {
      std::cout << i << std::endl;
      return 0;
    }
  }
  std::cout << -1 << std::endl;
  return 0;
}
