module kkk
sub main()
  
  dim h as long
  h = console.readline()
  dim i as long
  dim k as long
    dim ans as long
    
    do 
      k = h - 2^i
      if k < 0 then
        exit do
        end if
      i = i + 1
    loop
    
    ans = 2^i - 1
      console.writeline(ans)
    end sub
  end module