#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const double eps = 1e-9;
const double INF = inf;
const double EPS = eps;
int Q[123123], W[123123];
int calc(int v) {
  if (v % 2 == 1) return (v * (v - 1)) / 2 + 1;
  return (v * (v - 1) / 2) + v / 2;
}
int main() {
  int i, n, m;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) scanf("%d%d", &Q[i], &W[i]);
  sort(W, W + m);
  reverse(W, W + m);
  int cnt = 1;
  while (calc(cnt + 1) <= n) cnt++;
  cnt = min(cnt, m);
  long long res = 0;
  for (i = 0; i < cnt; i++) res += W[i];
  printf("%I64d\n", res);
  ;
  return 0;
}
