#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int q[maxn], w[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d%d", &q[i], &w[i]);
  sort(w, w + m);
  int ans = w[m - 1], c = 2;
  for (int i = m - 2; i >= 0; i--) {
    if (c % 2 == 1) {
      if (c * (c - 1) / 2 + 1 <= n)
        ans += w[i];
      else
        break;
    } else {
      if (c * c / 2 <= n)
        ans += w[i];
      else
        break;
    }
    c++;
  }
  printf("%d\n", ans);
  return 0;
}
