#include <bits/stdc++.h>
using namespace std;
int N;
inline bool check(int x) {
  long long t = (long long)x * (long long)(x - 1) / 2;
  if (x & 1)
    t++;
  else
    t += x / 2;
  return t <= N;
}
int main() {
  int M;
  scanf("%d%d", &N, &M);
  vector<int> A;
  for (int i = 0; i < M; i++) {
    int x;
    scanf("%*d%d", &x);
    A.push_back(x);
  }
  sort(A.begin(), A.end(), greater<int>());
  int lb = 1, rb = M;
  while (lb < rb) {
    int mid = (lb + rb + 1) >> 1;
    if (check(mid))
      lb = mid;
    else
      rb = mid - 1;
  }
  long long ans = 0;
  for (int i = 0; i < lb; i++) ans += A[i];
  printf("%lld\n", ans);
  return 0;
}
