const exec = (input) => {
  const cubes = input.split("").filter((i) => {
    return !isNaN(parseInt(i))
  })
  if (cubes.length < 1) {
    return input
  }
  const p = cubes
    .map((c, i, arr) => {
      if (arr[i + 1] === undefined) {
        return null
      }
      return {
        arr: [arr[i], arr[i + 1]],
        i: i
      }
    })
    .filter((i) => !!i)
  const a = p.find((p) => p.arr[0] != p.arr[1])
  if (!a) {
    return input
  }
  const next = [...cubes.slice(0, a.i), ...cubes.slice(a.i + 2)].join("")
  if (next == "") {
    return next
  }
  return exec(next)
}

// @ts-ignore
require("fs").readFile("/dev/stdin", "utf8", (err, input) => {
  const inp = input.replace("\n", "")
  const cnt = exec(inp)
  console.log(inp.length - cnt.length)
})
