#include <bits/stdc++.h>
using namespace std;
long long n, m, a[200005], x[200005], y[200005];
long long check(long long t) {
  if (t % 2 == 1)
    return (t * t - t + 2) / 2;
  else
    return (t * t) / 2;
}
int main(int argc, char *argv[]) {
  long long res = 0;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> x[i] >> y[i];
  sort(y + 1, y + 1 + m);
  int tmp;
  for (tmp = m; tmp >= 1; tmp--)
    if (check(tmp) <= n) break;
  for (int i = m; i >= m - tmp + 1; i--) res += y[i];
  cout << res;
  return 0;
}
