#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
pair<int, int> tab[N];
long long int ilosc(int a) {
  if (a % 2)
    return (long long)a * (a - 1) / 2 + 1;
  else
    return (long long)a * (a - 1) / 2 + a / 2;
}
int main() {
  int n, m;
  long long int wynik = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d%d", &tab[i].second, &tab[i].first);
  sort(tab, tab + m);
  int p = 1, k = n;
  while (p < k) {
    if (ilosc((p + k + 1) / 2) > n)
      k = (p + k + 1) / 2 - 1;
    else
      p = (p + k + 1) / 2;
  }
  for (int i = 0; i < min(p, m); i++) wynik += tab[m - 1 - i].first;
  printf("%I64d\n", wynik);
}
