#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  std::vector<int> a(m);
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d %d", &x, &a[i]);
  }
  sort((a).begin(), (a).end());
  reverse((a).begin(), (a).end());
  int k = 1;
  while (1) {
    int l = k + 1;
    if (l % 2 == 0) {
      if (l * l / 2 <= n)
        k = l;
      else
        break;
    } else {
      if (l * (l / 2) + 1 <= n)
        k = l;
      else
        break;
    }
  }
  long long ans = 0;
  for (int i = 0; i < min(m, k); i++) {
    ans += (long long)a[i];
  }
  cout << ans;
}
