program fifth
  implicit none
  character(200000) :: s
  integer :: n, c, i, k, k2
  logical :: t, t2

  read(*,*) s

  n = len(s)
  c = 0
  t = .true.

  
  do while(t)
  do i = 1, n
     if (s(i:i) == 'B' .and. s(i+1:i+1) == 'W') then
        s(i:i) = 'W'
        s(i+1:i+1) = 'B'
        c = c + 1
     end if

  end do
  k2 = index(s, 'BW')
  if (k2 > 0) then
     cycle
  end if

  
  k = index(s, 'WB')
  do i = k+2, n
     if (s(i:i) /= 'W') then
        t2 = .false.
     else
        t2 = .true.
     end if
  end do

  t = t2
  
end do

write(*,*) c
stop
end program fifth

