#include <bits/stdc++.h>
using namespace std;
int n, m, w[100005], a;
int licz(int q) {
  if (q == 2) return 2;
  int wyn = q * (q - 1) / 2;
  if (q % 2 == 0) return wyn + q / 2;
  return wyn + 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) scanf("%d%d", &a, &w[i]);
  sort(w, w + m);
  int ile = 1;
  while (licz(ile) <= n) ++ile;
  long long wyn = 0LL;
  for (int i = m - 1; i >= max(m - ile + 1, 0); i--) wyn += w[i];
  cout << wyn << endl;
}
