n = gets.chomp.to_i b0 = 1 res = 0 while true break if b0 == n b1 = b0 0.upto(b1) do |i| b2 = b1 - i b3 = b2 * 2 + i if b3 <= n then b0 = b3 break end end res += 1 end puts res