program collatz_problem
  implicit none
  integer :: s, u(1000000) = -1, i = 1
  read(*,*) s
  u(s) = 1
  do
    i = i+1
    s = merge(s/2,3*s+1,mod(s,2) == 0)
    if (u(s) > 0) exit
    u(s) = i
  end do
  write(*,'(i0)') i
end program collatz_problem