#include <bits/stdc++.h>
using namespace std;
int solve(int n) {
  int lo = 1, hi = 3000;
  while (lo < hi) {
    int mid = (lo + hi + 1) / 2;
    int len = 0;
    if (mid % 2 == 0) {
      len = mid * mid / 2;
    } else {
      len = mid * (mid - 1) / 2 + 1;
    }
    if (len <= n) {
      lo = mid;
    } else {
      hi = mid - 1;
    }
  }
  return lo;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int *arr = new int[m];
  for (int i = 0; i < m; i++) {
    cin >> arr[i] >> arr[i];
  }
  sort(arr, arr + m);
  int len = solve(n);
  long long exp = 0;
  for (int i = max(m - len, 0); i < m; i++) {
    exp += arr[i];
  }
  cout << exp;
  return 0;
}
