#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int num[maxn];
int main() {
  int i, j, m, d, x, y, n, p;
  while (cin >> n >> m) {
    for (i = 1; i <= m; i++) scanf("%d%d", &p, &num[i]);
    sort(num + 1, num + 1 + m, greater<int>());
    long long l = 1, r = m, mid;
    while (l < r) {
      mid = (l + r + 1) / 2;
      if (mid % 2) {
        long long q = (mid) * (mid - 1) / 2;
        if (q <= n - 1)
          l = mid;
        else
          r = mid - 1;
      } else {
        long long q = (mid) * (mid - 1) / 2 + (mid / 2 - 1);
        if (q <= n - 1)
          l = mid;
        else
          r = mid - 1;
      }
    }
    long long ans = 0;
    for (i = 1; i <= l; i++) ans += num[i];
    cout << ans << endl;
  }
  return 0;
}
