#include <bits/stdc++.h>
using namespace std;
const double eps(1e-8);
int ans[5001000];
long long q[100010], w[100010];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%I64d %I64d", q + i, w + i);
  sort(w + 1, w + m + 1);
  int last = 6;
  ans[1] = 1;
  ans[2] = 2;
  ans[3] = 2;
  ans[4] = 3;
  ans[5] = 3;
  for (int len = 3; len <= 2200; len++) {
    if (len & 1) {
      while (last < len * (len - 1) / 2 + 1) {
        ans[last] = len - 1;
        last++;
      }
    } else {
      int need = len * (len - 1) / 2 - (len / 2 - 1) + 1 + (len / 2 - 1) * 2;
      while (last < need) {
        ans[last] = len - 1;
        last++;
      }
    }
  }
  int cnt = ans[n];
  long long res = 0;
  for (int i = 1; i <= min(m, cnt); i++) res += w[m - i + 1];
  printf("%I64d\n", res);
  return 0;
}
