#include <bits/stdc++.h>
using namespace std;
int w[1000001];
bool _func(int a, int b) { return a > b; }
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int q;
    scanf("%d%d", &q, &w[i]);
  }
  sort(w, w + m, _func);
  long long int ans = 0;
  for (int i = 0; i < m; i++) {
    int term;
    if (i & 1)
      term = 2 * ((i + 1) / 2) * ((i + 1) / 2);
    else
      term = 2 * (i / 2) * (i / 2) + (i / 2) + 1;
    if (term > n) break;
    ans += (long long int)w[i];
  }
  cout << ans << endl;
  return 0;
}
