MAX = 151200

def lower(n, arr)
  l = -1; r = arr.size
  while l + 1 < r
    m = (l + r) / 2
    arr[m] <= n ? l = m : r = m
  end
  arr[l]
end

cube = (0..53).map{ |i| i ** 3 }
tetra = (0..95).map{ |i| i * (i + 1) * (i + 2) / 6 }

a = []
cube.each do |c|
  tetra.each do |t|
    break if c + t > MAX
    a << c + t
  end
end
a.sort!.uniq!
while n = gets.to_i
  break if n == 0
  puts lower(n, a)
end