#include <bits/stdc++.h>
const int N = 100100;
int cot[N];
struct node {
  int id, w;
} p[N];
int cmp(void const *a, void const *b) {
  node *c, *d;
  c = (node *)a;
  d = (node *)b;
  return d->w - c->w;
}
int find(int n) {
  int L = 1, R = 2001, mid;
  int flag = 1;
  while (L <= R) {
    mid = (L + R) >> 1;
    if (cot[mid] <= n) {
      flag = mid;
      L = mid + 1;
    } else
      R = mid - 1;
  }
  return flag;
}
int main() {
  int n, m, i, sum = 3, g, k = 1;
  cot[1] = 1;
  cot[2] = 2;
  for (i = 3; i <= 2001; i++) {
    cot[i] = sum + 1;
    if (i % 2 == 0) {
      cot[i] += k;
      k++;
    }
    sum += i;
  }
  while (scanf("%d%d", &n, &m) != -1) {
    for (i = 0; i < m; i++) scanf("%d%d", &p[i].id, &p[i].w);
    qsort(p, m, sizeof(p[0]), cmp);
    g = find(n);
    if (g > m) g = m;
    sum = 0;
    for (i = 0; i < g; i++) sum += p[i].w;
    printf("%d\n", sum);
  }
  return 0;
}
