#include <bits/stdc++.h>
using namespace std;
long long a[20 * 100005], p[100005];
int main() {
  long long i, j, k, n, m, x, y;
  p[1] = 1;
  p[2] = 2;
  p[3] = 4;
  for (i = 4; i < 100005; i++) {
    p[i] = i * (i / 2) + i % (i / 2);
  }
  while (cin >> n >> m) {
    for (i = 0; i < m; i++) {
      cin >> x >> y;
      a[i] = y;
    }
    sort(a, a + m);
    reverse(a, a + m);
    long long flg = 0;
    for (i = 1; i <= m; i++) {
      if (p[i] > n) {
        flg = 1;
        break;
      }
    }
    if (flg) {
      m = i - 1;
    }
    x = 0;
    for (i = 0; i < m; i++) {
      x += a[i];
    }
    cout << x << endl;
  }
  return 0;
}
