#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dx[] = {-1, 0, 1, 0};
long long dy[] = {0, -1, 0, 1};
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > v(m);
  for (long long i = 0; i < m; i++) {
    cin >> v[i].second >> v[i].first;
  }
  sort(v.rbegin(), v.rend());
  long long ans = v[0].first;
  for (long long k = 2; k <= m; k++) {
    if (max((k * (k - 1)) / 2 + 1, k * (k / 2)) <= n)
      ans += v[k - 1].first;
    else
      break;
  }
  cout << ans << "\n";
}
