#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
long long cont(long long n) {
  long long ans = (n - 1);
  ans = ans * (n / 2);
  ans += ((n + 1) / 2);
  return ans;
}
long long solve(long long aval, long long mx) {
  long long lo = 1, hi = mx;
  for (long long i = mx; i >= 1; i--)
    if (cont(i) <= aval) return i;
  return lo;
}
vector<long long> tp;
int main() {
  ios_base::sync_with_stdio(0);
  long long aval, m;
  cin >> aval >> m;
  tp.resize(m);
  int a;
  for (int i = 0; i < m; i++) {
    cin >> a >> tp[i];
  }
  sort(tp.begin(), tp.end());
  reverse(tp.begin(), tp.end());
  long long can = solve(aval, m);
  long long ans = 0;
  for (int i = 0; i < can; i++) ans += tp[i];
  cout << ans << endl;
  return 0;
}
