def main(argv)
  s = STDIN.gets.chomp
  c = 0
  
  t1 = s.gsub(/^T+/, '')
  c += s.size - t1.size
  
  t2 = t1.gsub(/S+$/, '')
  c += t1.size - t2.size
  
  sn = 0
  tn = 0
  
  t2.split('').each do |a|
    if a == 'S' then
      sn += 1
    else
      tn += 1
    end
  end
  
  c += (sn - tn).abs

  STDOUT.puts c.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end