#include <stdio.h>

int main(void){
	int i,j;
	int n,cube,tetra;
	int max;

	while(scanf("%d",&n) && n){
		max = 0;
		for(i=0;(cube=i*i*i)<=n;i++){
			for(j=0;cube+(tetra=j*(j+1)*(j+2)/6)<=n;j++){
				if(cube + tetra > max) max = cube + tetra;
			}
		}
		printf("%d\n",max);
	}

	return 0;
}