import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    S = in_s()
    N = len(S)

    lt = 0
    rs = 0
    for i in range(N):
        if S[i] == 'T':
            lt += 1
        else:
            break
    for i in range(N - 1, -1, -1):
        if S[i] == 'S':
            rs += 1
        else:
            break

    snum = N // 2 - rs
    tnum = N // 2 - lt
    cnum = min(snum, tnum)
    ans = N - cnum * 2
    print(ans)


if __name__ == '__main__':
    main()
