def main():
    #input data
    import sys
    input = lambda:sys.stdin.readline().strip()
    S = input()
    
    #solve
    from itertools import groupby
    def runLengthEncode(S: str)->list:
        '''
        str to list(tuple).required itertools.groupby
        '''
        grouped = groupby(S)
        res = []
        for k, v in grouped:
            res.append((k, len(list(v))))
        return res

    S = runLengthEncode(S)
    ans = 0

    idx=0
    while idx<len(S):
        if idx<len(S)-1:
            if S[idx][0]=='S' and S[idx+1][0]=='T':
                ans+=abs(S[idx][1]-S[idx+1][1])
                idx+=2
                continue
        ans+=S[idx][1]
        idx+=1
    print(ans)

if __name__=='__main__':
    main()