s=list(input())
word,cnt=s[0],0
n=len(s)
S=""
for i in range(n):
    if word!=s[i]:
        S +=word+str(cnt)
        cnt=1
        word=s[i]
    else:
        cnt +=1
S +=word+str(cnt)
S +="G"
S=list(S)
cnt=0
for i in range(0,len(S)-1,2):
    if S[i]+S[i+2]=="ST":
        cnt +=(min(int(S[i+1]),int(S[i+3])))*2
print(n-cnt)