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

    while S:
        x = S.pop(0)
        if S:
            if x[0]=='S' and S[0][0]=='T':
                y = S.pop(0)
                ans += abs(x[1]-y[1])
            else:
                ans += x[1]
        else:
            ans += x[1]
    print(ans)


if __name__=='__main__':
    main()