#include <bits/stdc++.h>
using namespace std;
long long int n, m, val[100100];
void print(long long int ind) {
  long long int acm = 0;
  for (int i = 0; i < ind; i++) {
    acm += val[i];
  }
  cout << acm << endl;
}
int main() {
  cin >> n >> m;
  for (long long int x, i = 0; i < m; i++) {
    scanf("%I64d %I64d", &x, &val[i]);
  }
  sort(val, val + m, greater<long long int>());
  for (long long int i = m; i > 0; i--) {
    if ((i % 2 && (i * (i - 1)) / 2 + 1 <= n) ||
        (!(i % 2) && (i * (i - 1)) / 2 + i / 2 <= n)) {
      print(i);
      break;
    }
  }
  return 0;
}
