#include <bits/stdc++.h>
using namespace std;
vector<int> V;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, x = 0;
  long long w = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    V.push_back(b);
  }
  sort(V.begin(), V.end());
  if (n == 1) x = 1;
  if (n > 1 && n < 4) x = 2;
  if (n > 3 && n < 8) x = 3;
  if (n >= 8) {
    bool b = 1;
    x = 4;
    while (b) {
      int a = x * (x / 2);
      if (x % 2 == 1) a++;
      if (a > n)
        b = 0;
      else
        x++;
    }
    x--;
  }
  for (int i = m - 1; i >= max(m - x, 0); i--) w += (long long)V[i];
  cout << w << "\n";
  return 0;
}
