#include <bits/stdc++.h>
using namespace std;
int q[100005];
int n, m;
bool ok(long long x) {
  if (x & 1) return x * (x - 1) / 2 + 1 <= n;
  return x * x / 2 <= n;
}
int main(void) {
  scanf("%d%d", &n, &m);
  int bla;
  for (int i = 1; i <= m; i++) scanf("%d%d", &bla, &q[i]);
  sort(q + 1, q + m + 1, greater<int>());
  int i;
  for (i = 2; i <= m; i++)
    if (!ok(i)) break;
  long long sol = 0;
  for (int j = 1; j < i; j++) sol += q[j];
  printf("%I64d\n", sol);
  return 0;
}
