#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 100;
long long n, m;
struct node {
  long long q, w;
} sh[N];
bool cmp(node a, node b) { return a.w > b.w; }
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
inline long long f(long long x) {
  if (x & 1) return x * (x - 1) / 2;
  return x * (x - 1) / 2 + x / 2 - 1;
}
signed main() {
  n = read();
  m = read();
  for (long long i = 1; i <= m; i++) sh[i] = (node){read(), read()};
  sort(sh + 1, sh + 1 + m, cmp);
  long long MAX = 0, sum = 0;
  for (long long i = 1; i <= m; i++) {
    sum += sh[i].w;
    if (f(i) + 1 <= n) MAX = max(MAX, sum);
  }
  printf("%lld\n", MAX);
}
