#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 3e6 + 10;
int a[N];
int read(void) {
  int s = 0, w = 0;
  char c = getchar();
  while (c < '0' || c > '9') w |= c == '-', c = getchar();
  while (c >= '0' && c <= '9') s = s * 10 + c - 48, c = getchar();
  return w ? -s : s;
}
int point(int x) {
  if (x % 2 == 1) return x * (x - 1) / 2 + 1;
  if (x % 2 == 0) return x * (x - 1) / 2 + x / 2;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int q = read();
    a[i] = read();
  }
  sort(a + 1, a + m + 1);
  reverse(a + 1, a + m + 1);
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    if (point(i) > n) return cout << sum, 0;
    sum += a[i];
  }
  cout << sum << endl;
  return 0;
}
