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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine();
            var acum = new int[x.Length + 1];
            var index = x[0] == 'T' ? 0 : 1;
            acum[index]++;

            for (var i = 1; i < x.Length; i++)
            {
                if (x[i] != x[i - 1])
                {
                    index++;
                    acum[index] = 1;
                }
                else
                    acum[index]++;
            }

            for (var i = 2; i < x.Length; i+=2)
            {
                var min = Math.Min(acum[i], acum[i - 1]);
                acum[i] -= min;
                acum[i - 1] -= min;
            }

            Console.WriteLine(acum.Sum());
        }
    }
}
