s = gets.chomp

tf = true
sf = true

ti = 0
si = 0
while tf || sf do
  if tf && s[ti]=='T' then
    ti+=1
  else
    tf = false
  end
  if sf && s[-si-1]=='S' then
    si+=1
  else
    sf = false
  end
end

puts [[ti,si].max*2, s.size-20000].max