lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end require "big" def calc(n : BigInt, k : Int32) res = 0.to_big_i k.times do |i| return -1 if n == 0 res += n n //= 2 end return res end n = read_line.to_big_i puts (1..64).reverse_each.map { |k| val = (1.to_big_i..n).bsearch { |first| calc(first, k) >= n } [val && calc(val, k) == n, val] }.find { |v| v[0] }.not_nil![1]