#include <bits/stdc++.h>
int main() {
  int n, m, s, c, sum[] = {0, 0, 0};
  std::cin >> n >> m;
  if (m == 0) {
    if (n == 3)
      sum[0] = 100;
    else if (n == 2)
      sum[1] = 10;
  }
  for (int i = 0; i < m; i++) {
    std::cin >> s >> c;
    if (s == 1)
      sum[s - 1] = c * 100;
    else if (s == 2)
      sum[s - 1] = c * 10;
    else
      sum[s - 1] = c;
  }
  if (n == 3 && sum[0] == 0)
    std::cout << "-1\n";
  else if (n == 2 && sum[1] == 0)
    std::cout << "-1\n";
  else
    std::cout << sum[0] + sum[1] + sum[2] << std::endl;
  return 0;
}
