
object Main extends App {
  val s = scala.io.StdIn.readLine

  var now = s(0)
  var b_cnt = 0
  var w_cnt = 0

  s.foreach { ch =>
    if (now != ch) {
      if (now == 'B') {
        b_cnt += 1
      } else {
        w_cnt += 1
      }
      now = ch
    }
  }
  if (now == 'B') {
    b_cnt += 1
  } else {
    w_cnt += 1
  }

  def exec(wc: Int, bc: Int, top: (Char, Char)): Int = {
    if (wc == 0 || bc == 0) {
      return 0
    }

    var list = List[Int]()

    if (top._1 == 'W') {
      list = list.::(exec(wc - 1, bc, ('B', top._2)))
    }
    if (top._1 == 'B') {
      list = list.::(exec(wc, bc - 1, ('W', top._2)))
    }
    if (top._2 == 'W') {
      list = list.::(exec(wc - 1, bc, (top._1, 'B')))
    }
    if (top._2 == 'B') {
      list = list.::(exec(wc, bc - 1, (top._1, 'W')))
    }

    list.min + 1
  }

  println(exec(w_cnt, b_cnt, (s.head, s.last)))
}
