x = gets.chomp
tnum = 0
id = 0
x.each_char.with_index do |c, i|
  if c == "S"
    id = i
    break
  end
end
tnum = x[id..-1].count("T")
snum = 0
id = 0
x.reverse.each_char.with_index do |c, i|
  if c == "T"
    id = i
    break
  end
end
snum = x.reverse[id..-1].count("S")
p x.size - [tnum, snum].min * 2

