#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000 + 2;
int n;
int m;
pair<int, int> c[MAX];
int dp[MAX];
int main() {
  int i;
  cin >> n >> m;
  for ((i) = (1); (i) <= (m); ++(i)) scanf("%d%d", &c[i].second, &c[i].first);
  for ((i) = (1); (i) <= (m); ++(i)) {
    int p = (i - 1 + 1) / 2;
    int d = p * i;
    d = max(d, i * (i - 1) / 2 + 1);
    if (d > n) break;
  }
  int ans = 0;
  sort(c + 1, c + m + 1, greater<pair<int, int> >());
  for (i--; i; --i) ans += c[i].first;
  cout << ans << endl;
  return 0;
}
