#include <bits/stdc++.h>
using namespace std;
int W[100001];
int n, m;
long long needed(long long k) {
  if (k % 2 == 1) {
    return k * (k - 1) / 2 + 1;
  } else {
    return k * (k - 1) / 2 + (k - 2) / 2 + 1;
  }
}
long long solve(void) {
  long long k = 0;
  while ((k < m) && (needed(k + 1) <= n)) {
    ++k;
  }
  long long total = 0;
  for (int i = 0; i < k; ++i) {
    total += W[m - 1 - i];
  }
  return total;
}
int main(int argc, char *argv[]) {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int q;
    cin >> q >> W[i];
  }
  sort(W, W + m);
  long long sol = solve();
  cout << sol << endl;
  return 0;
}
