// Template for reading lines from stdin and printing the line count to stdout.
// Copy this code to your IDE to get started.

fun main() {
    val colors = "roygbvroygbv"
    val program = readln()!!.toMutableList()
    var colorIndex = 0
    var traveled = 0

    while(true) {
        val bestNextColors = colors.substring(colorIndex, colorIndex + 6)
        val nextColor = bestNextColors.firstOrNull { it in program } ?: break

        colorIndex = colors.indexOf(nextColor)
        traveled += 6 - bestNextColors.indexOf(nextColor)
        program -= nextColor
    }

    println(traveled)
}