#from collections import defaultdict





def main():

    ans=0

    tmp=0

    x=eval(input())

    for i in x:

        if tmp==0 and i=="T":

            ans+=1

        elif i=="T":

            tmp-=1

        else:

            tmp+=1

    print((ans*2))



if __name__ == '__main__':

    main()
import sys

input = sys.stdin.buffer.readline



#sys.setrecursionlimit(10**9)

#from functools import lru_cache



def RD(): return input().rstrip().decode()

def II(): return int(eval(input()))

def FI(): return int(eval(input()))

def MI(): return list(map(int,input().split()))

def MF(): return list(map(float,input().split()))

def LI(): return list(map(int,input().split()))

def LF(): return list(map(float,input().split()))

def TI(): return tuple(map(int,input().split()))

# rstrip().decode()



def main():

	x=RD()



	ans=0

	s=0



	for i in x:

		if i=="S":

			s+=1

		else:

			if s==0:

				ans+=1

			else:

				s-=1



	print((ans+s))



















if __name__ == "__main__":

	main()

# from collections import defaultdict
def main():
    ans = 0
    tmp = 0
    x = eval(input())
    for i in x:
        if tmp == 0 and i == "T":
            ans += 1
        elif i == "T":
            tmp -= 1
        else:
            tmp += 1
    print((ans * 2))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
    return input().rstrip().decode()


def II():
    return int(eval(input()))


def FI():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def MF():
    return list(map(float, input().split()))


def LI():
    return list(map(int, input().split()))


def LF():
    return list(map(float, input().split()))


def TI():
    return tuple(map(int, input().split()))


# rstrip().decode()
def main():
    x = RD()
    ans = 0
    s = 0
    for i in x:
        if i == "S":
            s += 1
        else:
            if s == 0:
                ans += 1
            else:
                s -= 1
    print((ans + s))


if __name__ == "__main__":
    main()

-# from collections import defaultdict +import sys + +input = sys.stdin.buffer.readline +# sys.setrecursionlimit(10**9) +# from functools import lru_cache +def RD(): +    return input().rstrip().decode() + + +def II(): +    return int(eval(input())) + + +def FI(): +    return int(eval(input())) + + +def MI(): +    return list(map(int, input().split())) + + +def MF(): +    return list(map(float, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +def LF(): +    return list(map(float, input().split())) + + +def TI(): +    return tuple(map(int, input().split())) + + +# rstrip().decode() +    x = RD() -    tmp = 0 -    x = eval(input()) +    s = 0 -        if tmp == 0 and i == "T": -            ans += 1 -        elif i == "T": -            tmp -= 1 +        if i == "S": +            s += 1 -            tmp += 1 -    print((ans * 2)) +            if s == 0: +                ans += 1 +            else: +                s -= 1 +    print((ans + s))