#include <bits/stdc++.h>
using namespace std;
const int MAX = 2000010;
int f(int n) { return n * (n - 1) / 2 + 1; }
int q[2010];
int u[200010];
int main() {
  int n, m, i;
  q[0] = 0;
  for (i = 1;; i++) {
    if (i & 1)
      q[i] = f(i);
    else
      q[i] = f(i) + i / 2 - 1;
    if (q[i] > MAX) break;
  }
  scanf("%d%d", &n, &m);
  int l = 0, r = i;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (n < q[mid])
      r = mid;
    else
      l = mid;
  }
  int g = l;
  if (n >= q[r]) g = r;
  for (i = 1; i <= m; i++) scanf("%d%d", &l, &u[i]);
  sort(u + 1, u + m + 1);
  int ans = 0;
  if (g > m) g = m;
  for (; g > 0; g--) ans += u[m + 1 - g];
  printf("%d", ans);
  return 0;
}
