#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
int main() {
  int N, m;
  cin >> N >> m;
  long long a[100100];
  for (int i = 0; i < (m); ++i) cin >> a[i] >> a[i];
  sort(a, a + m, greater<long long>());
  long long l = 0, r = N, mid;
  while (r - l > 1) {
    mid = (l + r) / 2;
    long long xx = 0;
    if (mid & 1)
      xx = mid * (mid - 1) / 2 + 1;
    else
      xx = mid * mid / 2;
    if (xx <= N)
      l = mid;
    else
      r = mid;
  }
  long long x = 0;
  if (r & 1)
    x = r * (r - 1) / 2 + 1;
  else
    x = r * r / 2;
  if (x <= N)
    mid = r;
  else
    mid = l;
  mid = min(mid, (long long)m);
  long long ans = 0;
  for (int i = 0; i < mid; ++i) ans += a[i];
  cout << ans << endl;
  return 0;
}
