#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 100 * 1000 + 9;
long long n, m;
pair<long long, long long> a[maxN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    long long q, w;
    cin >> q >> w;
    a[i] = make_pair(w, q);
  }
  sort(a + 1, a + m + 1);
  long long res = 0;
  for (long long i = m; i > 0; i--) {
    long long j = m - i;
    long long foo = 0;
    if (j & 1) {
      foo = (j * (j + 1)) / 2 + j / 2 + 1;
    } else {
      foo = (j * (j + 1)) / 2 + 1;
    }
    if (foo > n) {
      break;
    }
    res += a[i].first;
  }
  cout << res << '\n';
  return 0;
}
