#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, a[110001], ans;
bool cmp(int a, int b) { return a > b; }
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) scanf("%d%d", &j, &a[i]);
  sort(a + 1, a + 1 + m, cmp);
  for (i = 1;; i++) {
    if (i == 1)
      k = 1;
    else if (i == 2)
      k = 2;
    else {
      k = min((i - 2) * (i / 2) + 2 * (1 + (i - 1) / 2),
              (i - 1) * (i / 2) + (2 + (i - 2) / 2));
    }
    if (k > n) break;
  }
  k = i - 1;
  for (ans = 0, i = 1; i <= k; i++) ans += a[i];
  printf("%d\n", ans);
  return 0;
}
