read S
cnt=0
if [ "${S//B/}" = "" ] || [ "${S//W/}" = "" ]
then
	echo 0
	exit
fi

while :
do
	cnt=$((cnt + 1))
	if [ "${S::1}" = "B" ]
	then
		BK1=`echo ${S/W/ W} | awk '{print $2}'`
		BK2="${S/W*/}"
		BK2="${BK2//B/W}"
		S="W${BK2}${BK1}"
	else
		BK1=`echo ${S/B/ B} | awk '{print $2}'`
		BK2="${S/B*/}"
		BK2="${BK2//W/B}"
		S="B${BK2}${BK1}"
	fi
	
	if [ "${S//B/}" = "" ] || [ "${S//W/}" = "" ]
	then
		echo $cnt
		exit
	fi
done
