#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 1000 + 7;
long long n, m, ans, w[maxn];
bool cmp(long long x, long long y) { return x > y; }
long long lim(long long limit, long long r, long long l) {
  while (l + 1 < r) {
    long long mid = (l + r) >> 1;
    if (mid & 1) {
      long long tmp = (mid * (mid - 1)) >> 1;
      if (tmp <= limit)
        l = mid;
      else
        r = mid;
    } else {
      long long tmp = ((mid * (mid - 1)) >> 1) + mid / 2 - 1;
      if (tmp <= limit)
        l = mid;
      else
        r = mid;
    }
  }
  return l;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> w[i] >> w[i];
  sort(w, w + m, cmp);
  n = lim(n - 1ll, m + 1ll, 0ll);
  for (int i = 0; i < min(n, m); i++) ans += w[i];
  cout << ans << endl;
  return 0;
}
