#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e17;
const double DINF = numeric_limits<double>::max();
const int ITER = 300;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const int MAXN = 1e5 + 10;
int n, m;
vector<pair<int, int> > v;
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int q, w;
    cin >> q >> w;
    v.push_back({w, q});
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    long long cnt = i + 1;
    long long need =
        (cnt & 1) ? cnt * (cnt - 1) / 2 : cnt * (cnt - 1) / 2 + cnt / 2 - 1;
    if (need + 1 <= n) {
      ans += v[i].first;
    }
  }
  cout << ans << endl;
}
int main() {
  cout << setprecision(12) << fixed;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
