#include <bits/stdc++.h>
using namespace std;
inline int myrand() {
  return ((rand() & ((1 << 15) - 1)) << 15) ^ (rand() & ((1 << 15) - 1));
}
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<long long> cost;
  for (int i = 0; i < (m); ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    cost.push_back(b);
  }
  sort(cost.begin(), cost.end(), [](int a, int b) { return a > b; });
  int maks_k = 0;
  for (long long k = 1; k * (k - 1) / 2 + 1 <= n; k += 2)
    maks_k = max<long long>(maks_k, k);
  for (long long k = 2; k * (k - 1) / 2 + (k / 2) <= n; k += 2)
    maks_k = max<long long>(maks_k, k);
  maks_k = min(maks_k, m);
  long long suma = 0;
  for (int i = 0; i < (maks_k); ++i) suma += cost[i];
  cout << suma << endl;
  return 0;
}
