#include <bits/stdc++.h>
using namespace std;
long long n, m, p, q, k, b1;
string t;
long a[1000000] = {0}, b[100000] = {0};
long c[110][90001] = {0};
long d1 = 10000;
bool f(int a, int b) { return a > b; }
int main() {
  cin >> n >> m;
  long long j = 0;
  for (int k = 1; k <= m; ++k) cin >> b[k] >> a[k];
  sort(a + 1, a + m + 1, f);
  long long x = 1;
  while (1) {
    long long s = x * (x / 2) + x % 2;
    if (s > n) break;
    ++x;
  }
  x--;
  long long s = 0;
  for (int k = 1; k <= min(x, m); ++k) s += a[k];
  cout << s;
  return 0;
}
