#include <bits/stdc++.h>
using namespace std;
bool compare(pair<long long, long long>& a, pair<long long, long long>& b) {
  return a.second > b.second;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<pair<long long, long long>> a(m);
  for (auto& i : a) scanf("%lld %lld", &i.first, &i.second);
  sort(a.begin(), a.end(), compare);
  int nie = 1, nio = 2;
  int currlength = 1;
  int allowed = 0;
  while (n >= currlength) {
    allowed++;
    if (allowed & 1) {
      currlength += nie;
      nie += 3;
    } else {
      currlength += nio;
      nio++;
    }
  }
  long long tot = 0;
  for (int j = 0; j < allowed; j++) {
    if (j >= (int)a.size()) break;
    tot += a[j].second;
  }
  cout << tot << endl;
}
