#include <bits/stdc++.h>
using namespace std;
int n, m;
int k, w[100010];
long long ans;
int re(int r) {
  if (r % 2)
    return r * (r - 1) / 2 + 1;
  else
    return r * (r - 1) / 2 + (r / 2);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> k >> w[i];
  sort(w, w + m);
  int k = 1;
  while (re(k + 1) <= n) k++;
  k = min(k, m);
  for (int i = 0; i < k; i++) ans += w[m - i - 1];
  cout << ans << endl;
  return 0;
}
