#!/usr/bin/env python3



# from numba import njit



# input = stdin.readline



def calcGroup(s):

  whiteCount = 0

  blackCount = 0

  prev = ""

  for i in range(len(s)):

    if s[i] == prev:

      pass

    else:

      if s[i] == "W":

        whiteCount += 1

      elif s[i] == "B":

        blackCount += 1

      else:

        raise ValueError

    prev = s[i]

  return whiteCount,blackCount



# @njit

def solve(s):

  white,black = calcGroup(s)

  if abs(white-black) == 0:

    return (white-1)*2+1

  else:

    return min(white,black)*2







def main():

  s = eval(input())

  print((solve(s)))

  return



if __name__ == '__main__':

  main()

#!/usr/bin/env python3



# from numba import njit



# input = stdin.readline



def calcDivision(s):

  res = 0

  prev = ""

  for i in range(len(s)):

    if s[i] == prev:

      pass

    else:

      if prev == "":

        pass

      else:

        res += 1

    prev = s[i]

  return res



# @njit

def solve(s):

  return calcDivision(s)







def main():

  s = eval(input())

  print((solve(s)))

  return



if __name__ == '__main__':

  main()

#!/usr/bin/env python3
# from numba import njit
# input = stdin.readline
def calcGroup(s):
    whiteCount = 0
    blackCount = 0
    prev = ""
    for i in range(len(s)):
        if s[i] == prev:
            pass
        else:
            if s[i] == "W":
                whiteCount += 1
            elif s[i] == "B":
                blackCount += 1
            else:
                raise ValueError
        prev = s[i]
    return whiteCount, blackCount


# @njit
def solve(s):
    white, black = calcGroup(s)
    if abs(white - black) == 0:
        return (white - 1) * 2 + 1
    else:
        return min(white, black) * 2


def main():
    s = eval(input())
    print((solve(s)))
    return


if __name__ == "__main__":
    main()

#!/usr/bin/env python3
# from numba import njit
# input = stdin.readline
def calcDivision(s):
    res = 0
    prev = ""
    for i in range(len(s)):
        if s[i] == prev:
            pass
        else:
            if prev == "":
                pass
            else:
                res += 1
        prev = s[i]
    return res


# @njit
def solve(s):
    return calcDivision(s)


def main():
    s = eval(input())
    print((solve(s)))
    return


if __name__ == "__main__":
    main()

-def calcGroup(s): -    whiteCount = 0 -    blackCount = 0 +def calcDivision(s): +    res = 0 -            if s[i] == "W": -                whiteCount += 1 -            elif s[i] == "B": -                blackCount += 1 +            if prev == "": +                pass -                raise ValueError +                res += 1 -    return whiteCount, blackCount +    return res -    white, black = calcGroup(s) -    if abs(white - black) == 0: -        return (white - 1) * 2 + 1 -    else: -        return min(white, black) * 2 +    return calcDivision(s)