#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int C(int k) {
  if (k % 2)
    return (k * (k - 1)) / 2;
  else
    return (k * (k - 1)) / 2 + (k - 2) / 2;
}
int main() {
  int n, m, q;
  cin >> n >> m;
  vector<int> w(m);
  for (int i = 0; i < m; ++i) cin >> q >> w[i];
  sort(w.begin(), w.end());
  ;
  int k1 = 0, k2 = 1, k;
  while (C(k1 + 2) <= n - 1) k1 += 2;
  while (C(k2 + 2) <= n - 1) k2 += 2;
  k = max(k1, k2);
  long long ans = 0;
  for (int i = m - 1; i >= max(0, m - k); --i) ans += w[i];
  cout << ans;
}
