#include <bits/stdc++.h>
const int MAXN = 2e6 + 5;
using namespace std;
pair<int, int> arr[MAXN];
bool cmp(const pair<int, int> a, const pair<int, int> b) {
  return a.second > b.second;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int q, w;
    scanf("%d %d", &q, &w);
    arr[i] = {q, w};
  }
  sort(arr, arr + m, cmp);
  int N = (int(sqrt(8 * n - 7)) + 1) >> 1;
  long long ans = 0ll;
  int tmp = (N * (N - 1)) >> 1;
  if ((N & 1) == 0 && tmp + ((N - 1) >> 1) > n - 1) N--;
  for (int i = 0; i < min(N, m); i++) ans += (long long)arr[i].second;
  printf("%I64d\n", ans);
  return 0;
}
