#include <bits/stdc++.h>
using namespace std;
int w[100010];
bool cmp(int a, int b) { return a > b; }
int f(int x) {
  if (x == 0) return 0;
  if (x == 1) return 1;
  if (x % 2 == 1) {
    return x * (x - 1) / 2 + 1;
  }
  if (x % 2 == 0) {
    return x * (x - 1) / 2 + x / 2;
  }
}
int main() {
  int n, m;
  memset(w, 0, sizeof(w));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d%d", &x, &w[i]);
  }
  int t;
  for (t = 1; f(t) <= n; t++)
    ;
  t--;
  if (t > m) t = m;
  sort(w, w + m, cmp);
  int ans = 0;
  for (int i = 0; i < t; i++) ans += w[i];
  printf("%d", ans);
  return 0;
}
