#include <bits/stdc++.h>
using namespace std;
int licz(int n) {
  int res = 1;
  for (int k = (1); k <= (n); ++k) {
    if (k % 2 == 0) {
      if ((long long)k * (k - 1LL) / 2 + (k - 2) / 2 + 1 <= n)
        res = max(res, k);
    } else {
      if ((long long)k * (k - 1LL) / 2 + 1 <= n) res = max(res, k);
    }
  }
  return res;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int x = licz(n);
  vector<int> v;
  for (int i = 0; i < (m); ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    v.push_back(b);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long res = 0;
  for (int i = 0; i < (min((int)v.size(), x)); ++i) res += v[i];
  cout << res << endl;
  return 0;
}
