#include <bits/stdc++.h>
using namespace std;
const long long maxm = 3e5 + 5;
long long q[maxm];
long long w[maxm];
long long n, m;
bool cmp(long long a, long long b) { return a > b; }
void solve() {
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    cin >> q[i] >> w[i];
  }
  sort(w + 1, w + 1 + m, cmp);
  long long p = -1;
  for (long long i = 1; i <= m; i++) {
    long long t = 0;
    if (i & 1)
      t = i * (i - 1) / 2 + 1;
    else
      t = i * i / 2;
    if (t <= n) {
      p = i;
    } else {
      break;
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= min(m, p); i++) {
    ans += w[i];
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  solve();
  return 0;
}
