N=gets.chomp.to_i def nishinsuu(num) keta = 1 total = 0 while num > 0 num = num >> 1 keta += 1 end saidaiketa = keta - 1 amari = num % (2 ** saidaiketa) return (saidaiketa - 1) + amari end puts nishinsuu(N)