#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
string s;
long long q[N], w[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long ans = 0;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &q[i], &w[i]);
  }
  sort(w, w + m);
  reverse(w, w + m);
  for (int i = 0; i < min(n, m); ++i) {
    if ((i + 1) % 2 == 0) {
      if ((long long)(i + 1) * (long long)i / 2 + ((long long)(i + 1) / 2) <= n)
        ans += w[i];
      else
        break;
    } else {
      if ((long long)(i + 1) * (long long)i / 2 + 1 <= n)
        ans += w[i];
      else
        break;
    }
  }
  cout << ans;
  return 0;
}
