#include <bits/stdc++.h>
bool check(int s, int c, int num) {
  bool ret = false;
  int keta = 1;
  for (int i = 1; i < s; i++) {
    keta *= 10;
  }
  int sc = c * keta;
  int tmp = num % (keta);
  int tmp_num = num - tmp;
  tmp_num = tmp_num % (keta * 10);
  if (sc == tmp_num) {
    ret = true;
  }
  return ret;
}
int main() {
  int ans = -1;
  int N, M;
  std::cin >> N >> M;
  if (M == 0) {
    if (N == 1) {
      std::cout << 0 << std::endl;
      return 0;
    }
    ans = 1;
    for (int i = 0; i < N - 1; i++) {
      ans *= 10;
    }
    std::cout << ans << std::endl;
    return 0;
  }
  std::vector<int> s;
  std::vector<int> c;
  for (int i = 0; i < M; i++) {
    int tmps, tmpc;
    std::cin >> tmps >> tmpc;
    switch (tmps) {
      case 1:
        tmps = 3;
        break;
      case 2:
        tmps = 2;
        break;
      case 3:
        tmps = 1;
        break;
      case 4:
        std::cout << -1 << std::endl;
        return 0;
      case 5:
        std::cout << -1 << std::endl;
        return 0;
      default:
        tmps = 0;
        break;
    }
    s.push_back(tmps);
    c.push_back(tmpc);
  }
  for (int num = 1; num <= 999; num++) {
    bool isOk = false;
    for (int i = 0; i < M; i++) {
      isOk = check(s[i], c[i], num);
      if (isOk == false) {
        break;
      }
    }
    if (isOk == true) {
      int keta = 1;
      for (int i = 1; i < N; i++) {
        keta *= 10;
      }
      if (!(num > keta) || !(num < keta * 10)) {
        continue;
      }
      ans = num;
      break;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
