#include <bits/stdc++.h>
using namespace std;
const int MAXM = 100005;
int N, M;
int w[MAXM];
void load() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) scanf("%*d%d", w + i);
}
int f(int k) { return k * (k - 1) / 2 + (k % 2 ? 1 : k / 2); }
long long solve() {
  sort(w, w + M, greater<int>());
  long long sol = 0;
  for (int i = 0; i < M && f(i + 1) <= N; i++) sol += (long long)w[i];
  return sol;
}
int main() {
  load();
  printf("%I64d\n", solve());
  return 0;
}
