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