#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-13;
const long double PI = acos(-1);
const int INF = (int)1e9;
const long long INFF = (long long)1e18;
const int mod = (int)1e9 + 7;
const int MXN = (int)1e5 + 7;
int a[MXN];
int main(void) {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i < k + 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    a[i] = v;
  }
  sort(a + 1, a + k + 1, greater<int>());
  int ll = 1, rr = k, ok = 1;
  while (ll <= rr) {
    long long mid = (long long)(ll + rr) >> 1;
    long long v = mid * (mid / 2);
    if (mid % 2) v++;
    if (v > n)
      rr = mid - 1;
    else
      ok = mid, ll = mid + 1;
  }
  long long ans = 0;
  for (int i = 1; i < ok + 1; i++) ans += a[i];
  printf("%lld\n", ans);
  return 0;
}
