io = STDIN
x=io.gets.chomp
x.gsub!(/(ST)+/,"")
x.gsub!(/(S+)(T+)/) do |str|
  ssize = str.index("T")
  tsize = str.size - ssize
  if (ssize>tsize)
    "S" * (ssize-tsize)
  else
    "T" * (tsize-ssize)
  end
end
while x.gsub!(/(ST)+/,"")
end
puts x.size