#include <bits/stdc++.h>
using namespace std;
const int inft = 1000000009;
const int MAXN = 1000006;
pair<int, int> P[MAXN];
int deg[MAXN];
int n;
bool dasie(int w) {
  long long tot = 1LL * w * (w - 1) / 2;
  if (w % 2 == 0) tot += w / 2;
  if (w % 2 == 0) tot--;
  return tot <= n - 1;
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (m); ++i) scanf("%d%d", &P[i].second, &P[i].first);
  sort(P, P + m);
  reverse(P, P + m);
  int p = 0, k = m + 1;
  while (p + 1 < k) {
    int w = (p + k) / 2;
    if (dasie(w))
      p = w;
    else
      k = w;
  }
  long long sum = 0;
  for (int i = 0; i < (p); ++i) sum += P[i].first;
  printf("%lld\n", sum);
  return 0;
}
