#include <bits/stdc++.h>
using namespace std;
int A[200005];
int main() {
  int N, M, req, n;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; ++i) {
    int v;
    scanf("%d%d", &v, &A[i]);
  }
  sort(A, A + M);
  for (n = 1;; ++n) {
    if (n & 1)
      req = n * (n - 1) / 2 + 1;
    else
      req = n * n / 2;
    if (req > N) break;
  }
  --n;
  long long ans = 0;
  for (int i = M - 1; i >= max(0, M - n); --i) ans += A[i];
  printf("%I64d\n", ans);
}
