#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65777216")
using namespace std;
long long n, m;
pair<long long, long long> wq[1000000];
long long ans = 0;
bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
  return x >= y;
}
int z(long long f) {
  if (f % 2 == 1) {
    return f * (f - 1) / 2 + 1;
  } else {
    return f * f / 2;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> wq[i].second >> wq[i].first;
  }
  sort(wq, wq + m, cmp);
  long long l = 0, r = 100000;
  long long mid = (l + r) / 2;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    long long g = z(mid);
    if (g > n) {
      r = mid;
    } else {
      l = mid;
    }
  }
  long long ans = 0;
  for (int i = 0; i < min(l, m); i++) {
    ans += wq[i].first;
  }
  cout << ans;
}
