open System

let s = Console.ReadLine()

let ans =
    let bCompCnt, wCompCnt =
        let head =
            if s.[0] = 'B' then
                1, 0, 'B'
            else
                0, 1, 'W'

        [1 .. s.Length - 1]
        |> List.map (fun i -> s.[i])
        |> List.fold
            (fun (b, w, prevColor) c ->
                if prevColor = c then
                    b, w, c
                else
                    match c with
                    | 'B' -> (b + 1), w, 'B'
                    | _ -> b, (w + 1), 'W'
            ) head
        |> (fun (b, w, _) -> b, w)

    if bCompCnt = wCompCnt then
        2 * bCompCnt - 1
    else
        min bCompCnt wCompCnt
        |> fun n -> 2 * n

ans |> Console.WriteLine