#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int ar[m];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> ar[i];
  }
  sort(ar, ar + m);
  int ma = 0;
  ll su = 0;
  if (n < 3) {
    ma = n;
  } else {
    su = ma = 2;
    for (int i = 3;; i++) {
      su = (i * (i - 1)) >> 1;
      if (!(i & 1)) {
        su += i / 2 - 1;
      }
      su++;
      if (su > n) {
        break;
      }
      ma = i;
    }
  }
  ll ss = 0;
  for (int i = m - 1; max(m - ma, 0) <= i; i--) {
    ss += ar[i];
  }
  cout << ss << "\n";
}
