#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
struct node {
  int num, val;
  bool operator<(const node &b) const { return val > b.val; }
} a[maxn + 7];
long long C[maxn + 7];
int main() {
  long long n;
  int m;
  for (int i = 2; i <= maxn; i++) {
    C[i] = 1LL * i * (i - 1) / 2;
    if (i % 2 == 0)
      C[i] += i / 2;
    else
      C[i] += 1;
  }
  while (~scanf("%lld%d", &n, &m)) {
    for (int i = 1; i <= m; i++) {
      int x, y;
      scanf("%d%d", &a[i].num, &a[i].val);
    }
    sort(a + 1, a + 1 + m);
    if (n == 1) {
      printf("%d\n", a[1].val);
      continue;
    }
    int pos = 2;
    for (int i = 2; i <= maxn; i++) {
      if (C[i] <= n) pos = i;
    }
    long long ans = 0;
    for (int i = 1; i <= pos; i++) {
      ans += a[i].val;
    }
    cout << ans << endl;
  }
  return 0;
}
