#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000005;
struct abc {
  int x, y;
} a[maxn];
bool cmp(abc a1, abc b1) { return a1.y > b1.y; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ans;
  for (int i = 1; i <= m; ++i) scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + m + 1, cmp);
  long long l = 1, r = m, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (mid & 1) {
      if (mid * (mid / 2) + 1 <= (long long)n) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    } else {
      if (mid * (mid / 2) <= (long long)n) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
  }
  long long sum = 0;
  for (int i = 1; i <= ans; ++i) {
    sum += (long long)a[i].y;
  }
  printf("%I64d\n", sum);
  return 0;
}
