import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    X = input()
    N = len(X)
    cnt_s = 0
    cnt_t = 0
    flag = 0
    answer = 0
    for i in range(N):
        if X[i] == "S":
            cnt_s += 1
        elif X[i] == "T":
            cnt_t += 1
            if cnt_t > cnt_s:
                answer += cnt_t - cnt_s
                cnt_t = 0
                cnt_s = 0
            elif cnt_t == cnt_s:
                cnt_t = 0
                cnt_s = 0

    if cnt_s > 0:
        answer += cnt_s
    print(answer)


if __name__ == "__main__":
    main()
