#include <bits/stdc++.h>
using namespace std;
long long len(int n) {
  if (n % 2) return 1LL * n * (n - 1) / 2 + 1;
  return 1LL * n * (n - 1) / 2 + n / 2;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> w;
  for (int i = 0, x, y; i < m; ++i) scanf("%d%d", &x, &y), w.push_back(y);
  sort(w.rbegin(), w.rend());
  long long sum = 0;
  for (int i = 1; i <= m; ++i)
    if (len(i) <= n) sum += w[i - 1];
  cout << sum << endl;
  return 0;
}
