#include <bits/stdc++.h>
using namespace std;
long long int x[1000007], y[1000007], z[1000007];
string s, S;
long long int init(long long int n) {
  long long int i, j, k;
  for (i = 1; i <= 1000007 - 3; i++) {
    x[i] = (i / 2) * i;
    x[i] += (i % 2);
    if (x[i] > n) return i - 1;
  }
}
int main() {
  {
    long long int a = 0, b = 0, c = 0, d, diff, n, e, f, g, i, j, k, l, m, in,
                  mod, loc, p, q, r, u, val, w, t, tc, sz, lo, hi, mid,
                  mn = 2134567891, mx = 0, sum = 0, ans = 0;
    cin >> n >> q;
    k = init(n);
    for (i = 0; i < q; i++) {
      cin >> a >> z[i];
    }
    sort(z, z + q, greater<long long int>());
    for (i = 0; i < min(n, k); i++) {
      c += z[i];
    }
    cout << c << endl;
  }
  return 0;
}
