namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new A();
        }
    }

    class A
    {
        public A()
        {
            var str = Console.ReadLine();
            int cntS = 0;
            int cntT = 0;
            int amaruT = 0;
            foreach(var e in str)
            {
                if (e == 'S')
                    cntS++;
                else
                    cntT++;
                
                if (e == 'T' && cntS < cntT-amaruT)
                {
                    amaruT++;
                }
            }
            Console.WriteLine(amaruT*2);
        }
    }
}