#include <bits/stdc++.h>
using namespace std;
long long get(int n) {
  if (n % 2 == 0) return n * 1LL * (n - 1) / 2 + n / 2;
  return n * 1LL * (n - 1) / 2 + 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  int tmp;
  for (int i = 0; i < m; ++i) {
    cin >> tmp >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  int n_ = 1;
  while (get(n_) <= n) ++n_;
  --n_;
  a.resize(min(n_, (int)a.size()));
  cout << accumulate(a.begin(), a.end(), 0LL) << endl;
  return 0;
}
