#include <bits/stdc++.h>
using namespace std;
long long N, M;
vector<pair<int, int>> wq;
int main(int argc, const char* argv[]) {
  cin >> N >> M;
  for (int i = 0, w, q; i < M; i++) {
    cin >> q >> w;
    wq.push_back(pair<int, int>(w, q));
  }
  sort(wq.begin(), wq.end(), greater<pair<int, int>>());
  int idx = 1;
  for (; idx <= N + 1; idx++) {
    long long amt = 0;
    if (idx % 2 == 1)
      amt = ((long long)idx * (long long)(idx - 1) / (long long)2) + 1;
    else
      amt = ((long long)idx * (long long)(idx - 1) / (long long)2) + idx / 2;
    if (N < amt) {
      idx--;
      break;
    }
  }
  long long ANS = 0;
  for (long long i = 0; i < min((int)wq.size(), idx); i++) {
    ANS += (long long)wq[i].first;
  }
  cout << ANS << endl;
  return 0;
}
