s = list(str(input()))
n = len(s)
k = [ 0 for i in range(n) ]
for i in range(n):
    r = i
    l = i + 1   
    while True:
        if r < 0:
            r = 0
        if l > n - 1:
            l = n - 1
        if s[r] == "S" and s[l] == "T":
            if k[r] == 0 and k[l] == 0:
                k[r],k[l] = 1,1
            elif k[r] == 0 and k[l] == 1:
                l += 1
            elif k[r] == 1 and k[l] == 0:
                r -= 1
            elif k[r] == 1 and k[l] == 1:
                l += 1
                r -= 1
                if r < 0 and l > n - 1:
                    break 
        else:
            break
print(n - sum(k))