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

public class Hello
{
    public static void Main()
    {
        var a = Console.ReadLine().Trim();
        var st = new Stack<int>();
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] == 'S') st.Push(0);
            else if (a[i] == 'T' && (st.Peek() == 1 | st.Count() == 0)) st.Push(1);
            else if (a[i] == 'T' && st.Peek() == 0) st.Pop();
        }
        Console.WriteLine(st.Count());
    }
}
