#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using dd = long double;
namespace {
static bool constexpr dbg = 0;
ll constexpr N = 1.1e5;
ll n, m, w[N];
void init() {
  cin >> n >> m;
  for (ll i = 1; i <= (ll)(m); ++i) {
    ll _;
    cin >> _ >> w[i];
  }
}
void solve() {
  sort(w + 1, w + m + 1, greater<ll>());
  for (ll i = 1; i <= (ll)(m); ++i) w[i] += w[i - 1];
  ll res = 0;
  for (ll i = 1; i <= (ll)(m); ++i) {
    ll cnt = i & 1 ? (i * (i - 1) / 2 + 1) : i * i / 2;
    if (cnt <= n) res = i;
  }
  cout << w[res];
}
}  // namespace
int main() {
  if (!dbg) {
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  cout << fixed << setprecision(20);
  init();
  solve();
  return 0;
}
