program irreversible_operation
  implicit none
  character(len=200000) :: s
  integer, allocatable  :: a(:)
  integer               :: i, n, m, l
  read(*,*) s
  n = len_trim(s)
  allocate(a(n))
  do i = 1, n
     if (s(i:i) .eq. 'B') then
        a(i) = 0
     else
        a(i) = 1
     end if
  end do
  m = 0
  l = 0
  do
     do i = 1, n-1
        if (a(i)-a(i+1) .lt. 0) then
           a(i) = 1
           a(i+1) = 0
           m = m + 1
        end if
     end do
     if (l .eq. m) exit
     l = m
  end do
  deallocate(a)
  write(*,'(i0)') m
  stop
end program irreversible_operation