#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
int a[N];
bool check(long long x) {
  if (x & 1)
    return x * (x - 1) / 2 + 1 <= n;
  else
    return x * (x - 1) / 2 + 1 + (x - 2) / 2 <= n;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x;
    scanf("%d%d", &x, &a[i]);
  }
  sort(a + 1, a + m + 1, greater<int>());
  int l;
  for (l = m; l >= 0; --l) {
    if (check(l)) break;
  }
  long long ans = 0;
  for (int i = 1; i <= l; ++i) ans += a[i];
  cout << ans << endl;
  return 0;
}
