#include <bits/stdc++.h>
using namespace std;
#define MAX 151200
typedef long long ll;

int main(void){
  ll N;
  while(cin >> N, N){
    int ans = 0;
    for(int cube = 0; cube * cube * cube <= MAX; cube++){
      for(int tr = 0; tr * (tr+1) * (tr+2) / 6 <= MAX; tr++){
	int cuben = cube * cube * cube;
	int trn = tr*(tr+1)*(tr+2)/6;
	if(cuben <= N){
	  ans = max(ans, cuben);
	}
	if(trn <= N){
	  ans = max(ans, trn);
	}
	if(cuben + trn <= N){
	  ans = max(ans, cuben + trn);
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}