using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;


namespace tes
{
	class contest
	{
		static void Main(string[] args)
		{
			 
            string s = Console.ReadLine();

            int count = 0;
            int countS = 0;
            int countT = 0;
            bool S = false;
            for(int i =0; i<s.Length; i++)
            {
                if(s[i] == 'S' && countT == 0)
                {
                    countS++;
                }
                else if(s[i] == 'T' && countS>0)
                {
                    countT++;
                }

                if (s[i] == 'S' && countT>0 || i ==s.Length-1)
                {

                    count += (countS >= countT)? countT*2: countS*2 ;
                    countS = 1;
                    countT = 0;
                }

            }
            Console.WriteLine(s.Length-count);
		}				 
	}
}