import strutils
let x=stdin.readLine
var s=x.len
for i in 0..x.len-2:
  if x[i]=='S' and x[i+1]=='T':
    var
      j=i
      k=i+1
    while j>0 and x[j-1]=='S':j-=1
    while k<x.len-1 and x[k+1]=='T':k+=1
    s-=min(i-j+1,k-i)*2
echo s