#include <bits/stdc++.h>
using namespace std;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 100000000;
const int64_t BINF = 10000000000000001;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
const double pi = 3.14159265359;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pii> a(M);
  for (int i = 0; i < M; ++i) {
    cin >> a[i].first >> a[i].second;
  }
  std::sort(a.begin(), a.end());
  if (a[0].first == 1 && a[0].second == 0 && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  if (a[0].first == 1) ans = a[0].second * 100;
  for (int i = 1; i < M; ++i) {
    if (a[i].first == a[i - 1].first && a[i].second != a[i - 1].second) {
      cout << -1 << endl;
      return 0;
    } else {
      if (a[i].first == 2) {
        ans += a[i].second * 10;
      } else if (a[i].first == 3) {
        ans += a[i].second;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
