#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v(m);
  bool ans = true;
  int A = 0;
  for (int i = 0; i < (int)(m); i++) {
    int a, b;
    cin >> a >> b;
    v.at(i) = make_pair(a, b);
  }
  sort(v.begin(), v.end());
  if (v.at(0).second == 0)
    ans = false;
  else
    A += 100 * v.at(0).second;
  for (int i = 0; i < (int)(m - 1); i++) {
    if (v.at(i).first == v.at(i + 1).first) {
      if (v.at(i).second != v.at(i + 1).second) ans = false;
    } else {
      if (v.at(i + 1).first == 1)
        A += 100 * v.at(i + 1).second;
      else if (v.at(i + 1).first == 2)
        A += 10 * v.at(i + 1).second;
      else if (v.at(i + 1).first == 3)
        A += v.at(i + 1).second;
    }
  }
  if (ans)
    cout << A;
  else
    cout << -1;
}
