N = gets.to_i def f(d, l, x) return -Float::INFINITY if d >= x num = 0 n = 1 l.times do num += d * n n *= x end num end L = N.to_s(2).size ans = Float::INFINITY L.downto(1) do |l| 1.upto(9) do |d| ng = 1 ok = N + 1 while (ok - ng).abs >= 2 x = (ok + ng) / 2 if N <= f(d, l, x) ok = x else ng = x end end if f(d, l, ok) == N && ans > ok ans = ok end end end puts ans