#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int N, M;
int ar[MAXN];
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; ++i) {
    scanf("%d", ar + i);
    scanf("%d", ar + i);
  }
  sort(ar, ar + M);
  int num = 0;
  int val = 0;
  int nval = 0;
  int c2 = 0;
  while (nval <= N && num + 1 <= M) {
    val = nval;
    ++num;
    c2 += num;
    if ((num + 1) % 2 == 1)
      nval = c2 + 1;
    else
      nval = c2 + 1 + (num - 1) / 2;
  }
  long long ans = 0;
  for (int i = 0; i < num; ++i) {
    ans += ar[M - i - 1];
  }
  cout << ans << "\n";
  return 0;
}
