#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const long long int INFLL = 1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-14;
const long long int MOD = 1000000007;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
const int MAX_N = 100010;
long long int n, m;
long long int w[MAX_N];
long long int s = 0;
long long int ans;
int main() {
  scanf("%lld %lld", &n, &m);
  for (int i = (0); i < (int)(m); i++) scanf("%lld %lld", &ans, &w[i]);
  sort(w, w + m);
  reverse(w, w + m);
  for (int i = (1); i < (int)(MAX_N); i++) {
    if (i % 2 == 0) {
      if ((long long int)i * (long long int)i / 2 > n) {
        s = i - 1;
        break;
      }
    } else {
      if ((long long int)i * (long long int)(i - 1) / 2 + 1 > n) {
        s = i - 1;
        break;
      }
    }
  }
  ans = 0;
  for (int i = (0); i < (int)(min(s, m)); i++) ans += w[i];
  printf("%lld\n", ans);
  return 0;
}
