import sys

def input(): return sys.stdin.readline().rstrip()

from collections import Counter

def main():

    X=eval(input())

    cunt=0

    cunt_s=0

    for x in X:

        if x=='S':

            cunt_s+=1

        elif cunt_s>0:

            cunt_s-=1

        else:

            cunt+=1

    print((cunt+cunt_s))



if __name__=='__main__':

    main()
import sys

def input(): return sys.stdin.readline().rstrip()

from collections import deque

def main():

    X=eval(input())

    stack=deque()

    for x in X:

        if x=='S' or (x=='T' and (not stack or stack[-1]=='T')):

            stack.append(x)

        elif stack and stack[-1]=='S':

            stack.pop()

    print((len(stack)))

if __name__=='__main__':

    main()
import sys


def input():
    return sys.stdin.readline().rstrip()


from collections import Counter


def main():
    X = eval(input())
    cunt = 0
    cunt_s = 0
    for x in X:
        if x == "S":
            cunt_s += 1
        elif cunt_s > 0:
            cunt_s -= 1
        else:
            cunt += 1
    print((cunt + cunt_s))


if __name__ == "__main__":
    main()

import sys


def input():
    return sys.stdin.readline().rstrip()


from collections import deque


def main():
    X = eval(input())
    stack = deque()
    for x in X:
        if x == "S" or (x == "T" and (not stack or stack[-1] == "T")):
            stack.append(x)
        elif stack and stack[-1] == "S":
            stack.pop()
    print((len(stack)))


if __name__ == "__main__":
    main()

-from collections import Counter +from collections import deque -    cunt = 0 -    cunt_s = 0 +    stack = deque() -        if x == "S": -            cunt_s += 1 -        elif cunt_s > 0: -            cunt_s -= 1 -        else: -            cunt += 1 -    print((cunt + cunt_s)) +        if x == "S" or (x == "T" and (not stack or stack[-1] == "T")): +            stack.append(x) +        elif stack and stack[-1] == "S": +            stack.pop() +    print((len(stack)))