#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
  if (fabs(d) < eps) return 0;
  return d > eps ? 1 : -1;
}
const long long mod = 1000000007;
int n, m, ans;
int a[111111];
int f(int x) {
  if (x % 2 == 0) {
    x /= 2;
    return 2 * x * x + x + 1;
  } else {
    x++;
    x /= 2;
    return 2 * x * x;
  }
}
int main() {
  int i, j, k, cas;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%*d%d", a + i);
  }
  sort(a, a + m);
  reverse(a, a + m);
  int t;
  for (i = 1;; i++) {
    if (f(i - 1) <= n)
      t = i;
    else
      break;
  }
  long long sum = 0;
  for (i = 0; i < t && i < m; i++) sum += a[i];
  cout << sum << endl;
  return 0;
}
