import sys

sys.setrecursionlimit(10 ** 5 + 10)





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





def resolve():



    X = str(eval(input()))

    stack = 0

    pop = 0

    for i in range(len(X)):

        if X[i] == 'S':

            stack += 1

        elif X[i] == 'T' and stack > 0:

            pop += 1

            stack -= 1

    print((len(X)-pop*2))



resolve()
import sys

sys.setrecursionlimit(10 ** 5 + 10)





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





def resolve():



    # https://scrapbox.io/fukucchi/%E6%8B%AC%E5%BC%A7%E5%88%97%E3%81%AE%E6%95%B4%E5%90%88%E6%80%A7%E5%95%8F%E9%A1%8C

    # https://atcoder.jp/contests/abc064/tasks/abc064_d



    X = str(eval(input()))

    N = len(X)

    stack_rem = 0

    need_left = 0

    pop_cnt = 0



    for i in range(N):

        if X[i] == 'S':

            stack_rem += 1

        elif stack_rem > 0:

            stack_rem -= 1

            pop_cnt += 1

    print((N-pop_cnt*2))





resolve()
import sys

sys.setrecursionlimit(10**5 + 10)


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


def resolve():
    X = str(eval(input()))
    stack = 0
    pop = 0
    for i in range(len(X)):
        if X[i] == "S":
            stack += 1
        elif X[i] == "T" and stack > 0:
            pop += 1
            stack -= 1
    print((len(X) - pop * 2))


resolve()

import sys

sys.setrecursionlimit(10**5 + 10)


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


def resolve():
    # https://scrapbox.io/fukucchi/%E6%8B%AC%E5%BC%A7%E5%88%97%E3%81%AE%E6%95%B4%E5%90%88%E6%80%A7%E5%95%8F%E9%A1%8C
    # https://atcoder.jp/contests/abc064/tasks/abc064_d
    X = str(eval(input()))
    N = len(X)
    stack_rem = 0
    need_left = 0
    pop_cnt = 0
    for i in range(N):
        if X[i] == "S":
            stack_rem += 1
        elif stack_rem > 0:
            stack_rem -= 1
            pop_cnt += 1
    print((N - pop_cnt * 2))


resolve()

+    # https://scrapbox.io/fukucchi/%E6%8B%AC%E5%BC%A7%E5%88%97%E3%81%AE%E6%95%B4%E5%90%88%E6%80%A7%E5%95%8F%E9%A1%8C +    # https://atcoder.jp/contests/abc064/tasks/abc064_d -    stack = 0 -    pop = 0 -    for i in range(len(X)): +    N = len(X) +    stack_rem = 0 +    need_left = 0 +    pop_cnt = 0 +    for i in range(N): -            stack += 1 -        elif X[i] == "T" and stack > 0: -            pop += 1 -            stack -= 1 -    print((len(X) - pop * 2)) +            stack_rem += 1 +        elif stack_rem > 0: +            stack_rem -= 1 +            pop_cnt += 1 +    print((N - pop_cnt * 2))