#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > a;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x1, x2;
    cin >> x1 >> x2;
    a.push_back(pair<int, int>(-x2, x1));
  }
  sort(a.begin(), a.end());
  for (long long i = m; i >= 1; i--) {
    long long h = i * (i - 1) / 2 + 1;
    if ((i & 1) == 0) h += i / 2 - 1;
    if (h <= n) {
      long long ans = 0;
      for (int j = 0; j < i; j++) ans -= a[j].first;
      cout << ans;
      return 0;
    }
  }
  cout << 0;
}
