#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
pair<long long, long long> a[N];
long long n, m;
vector<long long> v;
long long solve(long long idx, long long go) {
  if (idx > 10) return 20;
  set<pair<long long, long long> > st;
  for (long long i = 0; i + 1 < v.size(); i++)
    st.insert({min(v[i], v[i + 1]), max(v[i], v[i + 1])});
  if (st.size() == go * (go - 1) / 2) return idx;
  long long ans = 20;
  for (long long i = 0; i < go; i++) {
    v.push_back(i);
    ans = min(ans, solve(idx + 1, go));
    v.pop_back();
  }
  return ans;
}
void get(long long go) { cout << solve(0, go) << '\n'; }
bool chk(long long x) {
  x--;
  if (x & 1) return (x + 1) * x / 2 + (x + 1) / 2 <= n;
  return (x + 1) * x / 2 + 1 <= n;
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) cin >> a[i].second >> a[i].first;
  sort(a, a + m);
  long long ans = 0;
  for (long long i = 1; i <= m; i++) {
    if (!chk(i)) break;
    ans += a[m - i].first;
  }
  cout << ans << '\n';
  return 0;
}
