#include<bits/stdc++.h>
using namespace std;
const int lim = 151200;

int main(){
  vector<int> cubic, tetra;
  for(int i=0;;i++){
    int x = i*i*i;
    if(x>lim)break;
    cubic.push_back(x);
  }

  for(int i=0;;i++){
    int x = i*(i+1)*(i+2)/6;
    if(x>lim)break;
    tetra.push_back(x);
  }

  vector<int> can;
  for(int i=0;i<(int)cubic.size();i++){
    for(int j=0;j<(int)tetra.size();j++){
      if(cubic[i] + tetra[j] > lim)break;
      can.push_back(cubic[i] + tetra[j]);
    }
  }

  sort(can.begin(),can.end());
  can.erase(unique(can.begin(),can.end()),can.end());

  int n;
  while(cin >> n, n){
    int p = upper_bound(can.begin(),can.end(),n) - can.begin();
    cout << can[p-1] << endl;
  }
}

  