#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  int s[M], c[M];
  int cur = 1;
  for (int i = 0; i < (int)(N - 1); i++) {
    cur *= 10;
  }
  int end = cur * 10;
  for (int i = 0; i < (int)(M); i++) std::cin >> s[i] >> c[i];
  bool b = true;
  while (cur < end) {
    for (int i = 0; i < M; i++) {
      auto str = std::to_string(cur);
      if (str[s[i] - 1] - '0' != c[i]) {
        b = false;
        break;
      }
    }
    if (b) {
      std::cout << cur;
      return 0;
    }
    b = true;
    ++cur;
  }
  std::cout << "-1";
  return 0;
}
