#include <bits/stdc++.h>
using ll = long long;
int main(int argc, char** argv) {
  int n, m;
  std::cin >> n >> m;
  int ans = -1;
  int d[] = {1, 0, 0};
  if (m == 0) {
    if (n == 3) {
      std::puts("100");
    } else if (n == 2) {
      std::puts("10");
    } else {
      std::puts("0");
    }
    return 0;
  }
  int flg[] = {0, 0, 0};
  for (int i = 0; i < m; i++) {
    int s, c;
    std::cin >> s >> c;
    if ((n > 1) && ((s == 1) && (c == 0))) {
      std::printf("-1\n");
      return 0;
    }
    if (flg[s - 1] == 0) {
      d[s - 1] = c;
      flg[s - 1] = 1;
      continue;
    }
    d[s - 1] = std::min(c, d[s - 1]);
  }
  int div = 1;
  if (n == 2) {
    div = 10;
  } else if (n == 1) {
    div = 100;
  }
  std::printf("%d\n", (d[0] * 100 + d[1] * 10 + d[2]) / div);
  return 0;
}
