#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int q[maxn], w[maxn];
inline long long calc(int x) {
  if (x & 1) return 1LL * x * (x - 1) / 2 + 1;
  return 1LL * x * (x - 1) / 2 + x / 2;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &q[i], &w[i]);
  int l = 1, r = m, ans = 1;
  while (l <= r) {
    int mid = l + r >> 1;
    if (calc(mid) <= n) {
      l = mid + 1;
      ans = mid;
    } else
      r = mid - 1;
  }
  sort(w + 1, w + m + 1, greater<int>());
  long long res = 0;
  for (int i = 1; i <= ans; i++) res += w[i];
  printf("%lld\n", res);
  return 0;
}
