program main

  implicit none

  integer(8)    :: h, i, n, num
  
  read(*,*) h

  n = 0   
  do 
    n = n + 1
    h = h / 2
    if( h <= 1 ) exit
  end do

  num = 1
  do i = 1, n
    num = num + 2**i
  end do
  print*, num


end program main
