#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, ll>;
int n, m;
vector<pii> coupons;
bool comp(pii a, pii b) { return a.second > b.second; }
ll getlen(ll x) {
  if (x % 2 == 1) return x * (x - 1) / 2 + 1;
  return x * (x - 1) / 2 + x / 2;
}
int main() {
  cin >> n >> m;
  ll low = 0, high = n;
  while (low < high) {
    ll mid = (low + high + 1) / 2;
    if (getlen(mid) <= n) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  for (int i = 0; i < m; i++) {
    ll q, w;
    cin >> q >> w;
    coupons.push_back({q, w});
  }
  sort(coupons.begin(), coupons.end(), comp);
  ll ans = 0;
  for (int i = 0; i < low && i < m; i++) {
    ans += coupons[i].second;
  }
  cout << ans << endl;
}
