#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int w[2000030];
int n, m;
bool cmp(int a, int b) { return a > b; }
int main() {
  int q;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &q, &w[i]);
  sort(w + 1, w + 1 + m);
  long long sum = 0;
  long long temp;
  for (int i = 1; i <= m; i++) {
    if (i % 2 == 0)
      temp = (i - 1) / 2 * i + i;
    else
      temp = (i - 1) / 2 * i + 1;
    if (temp <= n)
      sum += w[m - i + 1];
    else
      break;
  }
  printf("%I64d\n", sum);
  return 0;
}
