n = gets.to_i i = 1 j = 0 k = n - 1 min = i + j + k j = 2 i = (n ** (1.0 / j.to_f)).to_i k = n - i**j min = [min, i + j + k].min print i, "\n" while i >= 2 do j += 1 f = n ** (1.0 / j.to_f) i = f.ceil ** j > n ? f.floor : f.ceil k = n - i**j min = [min, i + j + k].min end puts min