S = input()
ans = 0
pos = 0
scount = 0

while pos < len(S):
    while pos <len(S) and S[pos] == 'T':
        pos += 1
        ans += 1
    if pos >= len(S):
        break

    while pos <len(S) and S[pos] == 'S':
        pos += 1
        scount += 1
    if pos >= len(S):
        ans += scount
        break

    tcount = 0
    while pos < len(S) and S[pos] == 'T':
        pos += 1
        tcount += 1
    if pos >= len(S):
        ans += abs(scount-tcount)
        break
      
    if scount >= tcount:
        scount = scount -tcount
    else: #scount < tcount
        ans += tcount-scount
        scount = 0

print(ans)
