#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > a;
long long sum, ans;
int e, deg;
int get_e(int num, int deg) {
  if (num == 1) return 0;
  if (num == 2) return 1;
  int res = num * (num - 1) / 2;
  if (deg & 1) {
    int bad = num - 2;
    res += bad / 2;
  }
  return res;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int q, w;
    scanf("%d %d", &q, &w);
    a.push_back(make_pair(w, q));
  }
  sort(a.rbegin(), a.rend());
  for (int i = 1; i <= min(3000, m); i++) {
    sum += a[i - 1].first;
    deg = i - 1;
    e = get_e(i, deg);
    if (e + 1 <= n) ans = max(ans, sum);
  }
  cout << ans;
  return 0;
}
