#include <bits/stdc++.h>
using namespace std;
long long n, m;
bool G(long long k) {
  if (k % 2 == 1 && ((k / 2) * k) == n) {
    return 0;
  }
  if (((k / 2) * k) <= n) {
    return 1;
  }
  return 0;
}
long long F(long long f, long long e) {
  long long mid = (f + e) / 2;
  if (e == f) {
    return f;
  }
  if (G(mid + 1)) {
    return F(mid + 1, e);
  }
  return F(f, mid);
}
vector<long long> l;
int main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long q, p;
    cin >> q >> p;
    l.push_back(p);
  }
  sort(l.begin(), l.end());
  long long ind = F(1, 100000);
  long long in = m - 1;
  long long ans = 0;
  while (ind && in != -1) {
    ind--;
    ans += (l[in]);
    in--;
  }
  cout << ans << endl;
  return 0;
}
