#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void mini(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void maxi(T &a, T b) {
  if (b > a) a = b;
}
int v[2005];
int main() {
  for (int k = 1; k < 2005; k++) v[k] = k * (k - 1) / 2 + (k % 2 ? 1 : k / 2);
  int n, m;
  cin >> n >> m;
  vector<int> w(m, 0);
  for (int i = 0; i < m; i++) {
    int q;
    scanf("%d%d", &q, &w[i]);
  }
  sort((w).begin(), (w).end());
  int k = upper_bound(v, v + 2005, n) - v - 1;
  mini(k, m);
  long long s = 0;
  for (int i = m - k; i < m; i++) s += w[i];
  cout << s << endl;
}
