#include <bits/stdc++.h>
using namespace std;
long long n, m, has, k, f[1010101], g[1010101];
vector<long long> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= 100000; i++) {
    if (i == 2) {
      f[i] = 2;
      g[i] = 1;
    } else if (i % 2 == 1)
      f[i] = 1 + (i * (i - 1)) / 2;
    else {
      g[i] = g[i - 2] + 4;
      f[i] = f[i - 2] + g[i];
      f[i] = 1 + (i * (i - 1)) / 2 + (i - 2) / 2;
    }
    if (f[i] <= n)
      k = i;
    else
      break;
  }
  for (long long i = 1; i <= m; i++) {
    long long ta;
    cin >> ta >> ta;
    v.push_back(ta);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (long long i = 0; i < min((long long)v.size(), k); i++) has += v[i];
  cout << has << "\n";
}
