X = input()

cnt = 0
cntT = 0
cntS = 0
for i in range(len(X)):
    if X[i] == 'T':
        cntT += 1
    if X[i] == 'S':
        cntS += 1
    if cntT > cntS + 1:
        cnt = cntS * 2
        cntS = 0
        cntT = 0
    if cntS == cntT == len(X) // 2:
        cnt = len(X)
        
print(len(X) - cnt)