#include <bits/stdc++.h>
using namespace std;
long long n, m, p[2000010];
vector<long long> w;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int foo, bar;
    cin >> foo >> bar;
    w.push_back(bar);
  }
  sort(w.begin(), w.end());
  reverse(w.begin(), w.end());
  long long final_num = 0;
  long long edge_num = n - 1;
  for (long long i = 1; i <= m; ++i) {
    long long now = i * (i - 1) / 2;
    if ((i & 1) == 0) now += i / 2 - 1;
    if (now <= edge_num) final_num = i;
  }
  long long ans = 0;
  for (int i = 0; i < final_num; ++i) {
    if (i == w.size()) break;
    ans += w[i];
  }
  cout << ans << '\n';
}
