#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m;
pair<long long, long long> arr[N];
bool cmp(pair<long long, long long> A, pair<long long, long long> B) {
  return A.second > B.second;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%lld%lld", &arr[i].first, &arr[i].second);
  }
  sort(arr + 1, arr + 1 + m, cmp);
  long long ans = 0, d = 0;
  int cnt = 0;
  for (int i = 1; i <= m; ++i) {
    cnt = (i * (i - 1)) / 2;
    if (!(i & 1)) cnt += (i - 2) / 2;
    if (cnt + 1 > n) break;
    d = i;
  }
  for (int i = 1; i <= d; ++i) ans += arr[i].second;
  printf("%lld\n", ans);
}
