#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383279;
const long double EPS = 1e-9;
const long long INF = 1e9 + 7;
const long long MOD = INF;
const long long maxn = 1e5 + 2;
const long long HASH_MODS[] = {1000000007333, 1000000009367, 1000000075747,
                               1000000158923, 1000000203119};
int val[maxn];
long long calc(long long limit, long long r) {
  ++r;
  long long l = 1;
  while (l < r - 1) {
    long long m = (l + r) >> 1;
    if (m & 1) {
      long long t = ((m - 1) * m) / 2;
      if (t <= limit)
        l = m;
      else
        r = m;
    } else {
      long long t = ((m - 1) * m) / 2 + (m / 2 - 1);
      if (t <= limit)
        l = m;
      else
        r = m;
    }
  }
  return l;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < (m); ++i) {
    int x;
    cin >> x >> val[i];
  }
  sort(val, val + m);
  reverse(val, val + m);
  n = calc(n - 1, m);
  long long ans = 0;
  for (int i = (0); i < (n); ++i) ans += val[i];
  cout << ans;
}
