#include <bits/stdc++.h>
using namespace std;
int n, m, tmp, c[100005], now, val;
long long cnt;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &tmp, &c[i]);
  }
  sort(c, c + m, greater<int>());
  while (val + 1 <= n) {
    now++;
    val = ((now) * (now - 1)) / 2;
    if (!(now % 2)) val += now / 2 - 1;
  }
  for (int i = 0; i < min(m, now - 1); i++) {
    cnt += c[i];
  }
  printf("%I64d\n", cnt);
}
