#include <bits/stdc++.h>
using namespace std;
const long V = 100001l;
long n, m, c[V];
long semieulerian(long v) {
  if (v % 2)
    return v * (v - 1) / 2 + 1;
  else
    return v * (v - 1) / 2 + (v - 2) / 2 + 1;
}
int main() {
  long v;
  cin >> n >> m;
  for (long i = 0; i < m; i++) cin >> v >> c[i];
  sort(c, c + m, greater<long>());
  long s = 0, j = 0;
  while (semieulerian(j + 1) <= n && j < m) s += c[j++];
  cout << s << endl;
  return 0;
}
