#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> q(m), w(m);
  for (int i = 0; i < m; i++) cin >> q[i] >> w[i];
  sort(w.rbegin(), w.rend());
  auto calc = [&](long long v) {
    return v * (v - 1) / 2 + (v & 1 ? 1 : v / 2);
  };
  while (calc(m) > n) m--;
  cout << accumulate(begin(w), begin(w) + m, 0LL) << endl;
  return 0;
}
