#include <bits/stdc++.h>
using namespace std;
int w[100050];
int cal(int i) {
  int summ = (i - 1) * i / 2;
  if (i & 1)
    return summ + 1;
  else
    return summ + i / 2;
}
int main() {
  int n, m, p, i, j, k;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; ++i) scanf("%*d%d", &w[i]);
  sort(w, w + m);
  reverse(w, w + m);
  int l = 0, r = 10000, mid;
  while (l + 1 < r) {
    mid = l + (r - l) / 2;
    if (cal(mid) > n)
      r = mid;
    else
      l = mid;
  }
  long long res = 0;
  for (i = 0; i < min(l, m); ++i) res += w[i];
  printf("%I64d", res);
  return 0;
}
