#include <bits/stdc++.h>
using namespace std;
int n, m, i, x, q, w[110000];
long long ans;
int f(int x) { return x * (x / 2) + x % 2; }
bool cmp(int x, int y) { return x > y; }
int main() {
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) scanf("%d%d", &q, w + i);
  sort(w, w + m, cmp);
  while (f(x + 1) <= n) x++;
  x = min(x, m);
  for (i = 0; i < x; i++) ans += w[i];
  printf("%I64d\n", ans);
  return 0;
}
