#include <bits/stdc++.h>
using namespace std;
class C_ {};
template <typename T>
C_& operator<<(C_& __m, const T& __s) {
  if (!1) cerr << "\E[91m" << __s << "\E[0m";
  return __m;
}
C_ merr;
struct __s {
  __s() {
    if (1) {
      ios_base::Init i;
      cin.sync_with_stdio(0);
      cin.tie(0);
    }
  }
  ~__s() {
    merr << "Execution time: " << fixed << setprecision(3)
         << (double)clock() / CLOCKS_PER_SEC << " s.\n";
  }
} __S;
int main(void) {
  int n, m;
  vector<pair<int, int> > V;
  long long nas = 0;
  long long p = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int q, w;
    cin >> q >> w;
    V.push_back(make_pair(w, q));
  }
  sort(V.begin(), V.end(), greater<pair<int, int> >());
  for (int i = 1; i <= n; i++) {
    long long need = (i * 1LL * (i - 1)) / 2LL;
    if (i - 1 >= (int)V.size()) break;
    p += V[i - 1].first;
    if (i % 2) {
      need++;
    } else {
      need += i / 2;
    }
    if (need <= n) {
      nas = max(nas, p);
    }
  }
  cout << nas << '\n';
  return 0;
}
