#include <bits/stdc++.h>
using namespace std;
long long w[1000001];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int tmp;
    scanf("%d%lld", &tmp, &w[i]);
  }
  sort(w, w + m);
  reverse(w, w + m);
  long long sol = 0;
  long long cur = 0;
  for (int i = 0; i < m; i++) {
    cur += w[i];
    long long x = i + 1;
    if (x & 1 && x * (x - 1) / 2 + 1 <= n)
      sol = max(sol, cur);
    else if (x % 2 == 0 && x * (x - 1) / 2 + x / 2 <= n)
      sol = max(sol, cur);
  }
  printf("%lld\n", sol);
  return 0;
}
