n=gets.to_i;m=n.bit_length;p (0..m).map{|i|(n>>i)-(i..m).reduce(0){|s,j|s+(n>>j+1)}}.max