#include <bits/stdc++.h>
struct card {
  int q, w;
} A[100000];
void qsort(int l, int r) {
  int x = l, y = r, m = A[(l + r) / 2].w;
  while (x <= y) {
    while (A[x].w > m) x++;
    while (A[y].w < m) y--;
    if (x <= y) {
      card t = A[x];
      A[x] = A[y];
      A[y] = t;
      x++;
      y--;
    }
  }
  if (x < r) qsort(x, r);
  if (l < y) qsort(l, y);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d %d", &A[i].q, &A[i].w);
  qsort(0, m - 1);
  long long ans = 0;
  long long x = 1;
  while ((x % 2 == 1 && x * (x - 1) / 2 + 1 <= n) ||
         (x % 2 == 0 && x * (x - 1) / 2 + x / 2 - 1 + 1 <= n)) {
    ans += A[x - 1].w;
    x++;
  }
  printf("%I64d", ans);
  return 0;
}
