#include <bits/stdc++.h>
using namespace std;
int n, m;
int w[10 + 100000];
int f[10 + 10000];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0), _b = m; i < _b; ++i) {
    int v;
    scanf("%d%d", &v, &w[i]);
  }
  sort(w, w + m);
  for (int k = (0), _b = 3000; k < _b; ++k)
    if (k & 1)
      f[k] = ((k - 1) * k) / 2 + 1;
    else
      f[k] = ((k - 1) * k) / 2 + 1 + (k - 2) / 2;
  int l = 1, r = 2990;
  while (l < r) {
    int m = (l + r) / 2;
    if (f[m] < n)
      l = m + 1;
    else
      r = m;
  }
  long long res = 0;
  if (f[l] > n) l -= 1;
  for (int i = (m - 1), _b = max(m - l, 0); i >= _b; --i) res += w[i];
  printf("%I64d\n", res);
  return 0;
}
