#include <bits/stdc++.h>
using namespace std;
long long i, n, m, k, a, b, sum;
vector<long long> num;
long long ans[5000];
int main() {
  cin >> n >> m;
  ans[0] = 1;
  for (i = 1; i <= 2100; i++)
    if (i % 2)
      ans[i] = ((i + 1) * (i + 1)) / 2;
    else
      ans[i] = 2 * ((i / 2) * (i / 2)) + (i / 2) + 1;
  for (i = 0; i <= 2100; i++)
    if (ans[i] > n) break;
  k = i;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    num.push_back(b);
  }
  sort(num.begin(), num.end());
  reverse(num.begin(), num.end());
  for (i = 0; i < min(k, m); i++) sum += num[i];
  cout << sum << endl;
}
