n = gets.to_i f = ->(n, k) { (1..k).sum { n > 0 ? n + 0 * (n /= 2) : -10**18 } } (1..64).reverse_each do |k| r = (1..n).bsearch { f[_1, k] >= n } puts(r) + exit if r && f[r, k] == n end