#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 1;
long long n, m;
bool check(long long i) {
  if (i & 1)
    return ((i * (i - 1)) / 2 + 1) <= n;
  else
    return ((i * (i - 1)) / 2 + i / 2) <= n;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  vector<long long> arr(m + 1);
  for (long long i = 1; i <= m; i++) {
    long long q, w;
    cin >> q >> w;
    arr[i] = w;
  }
  sort(arr.begin() + 1, arr.end(), greater<long long>());
  long long ans = 0;
  for (long long i = 1; i <= min(n, m); i++) {
    if (check(i)) ans += arr[i];
  }
  cout << ans;
  return 0;
}
