fun main(args: Array<String>) {
    agc005a()
}

fun agc005a() {
    val x = readLine()!!.map { it == 'T' }

    var remainS = 0
    var remainT = 0
    x.forEach { isT ->
        if (isT) {
            if (remainS > 0) remainS-- else remainT++
        } else {
            remainS++
        }
    }

    println(remainS + remainT)
}
