fun main(args: Array<String>) {
    val X = readLine()!!
    var cnt = 0
    var cntS = 0

    for (v in X) {
        when (v) {
            'S' -> {
                cntS++
            }
            'T' -> {
                if (cntS == 0) cnt++
                cntS = Math.max(0, cntS - 1)
            }
        }
    }
    println(cnt + cntS)
}
