// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int MAXN = 100005;

const int MOD = int(1e9) + 7;

const double PI = acos (-1.0);

const int INF = 0x3f3f3f3f;

const int dx[] = { -1, 0, 1, 0, 1, 1, -1, -1 };

const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };



template <class T> inline T min (T a, T b, T c) { return min (min (a, b), c); }

template <class T> inline T max (T a, T b, T c) { return max (max (a, b), c); }

template <class T> inline T min (T a, T b, T c, T d) { return min (min (a, b), min (c, d)); }

template <class T> inline T max (T a, T b, T c, T d) { return max (max (a, b), max (c, d)); }

template <class T> inline T min (T a, T b, T c, T d, T e) { return min (min (min (a, b), min (c, d)), e); }

template <class T> inline T max (T a, T b, T c, T d, T e) { return max (max (max (a, b), max (c, d)), e); }



string a;

bool vis[200005];

int main ()

{

    while (cin >> a)

    {

        memset(vis, 0, sizeof(vis));

        int lf, rg, end = a.length();

        lf = 0, rg = 1;

        int ans = end;

        while (rg < end)

        {

            if (a[lf] == 'S' && a[rg] == 'T')

            {

                vis[lf] = vis[rg] = 1;

                ans -= 2;

                while(lf >= 0 && vis[lf]) --lf;

                ++rg;

                while (lf >= 0 && rg < end)

                {

                    if(vis[lf])

                    {

                        --lf;

                        continue;

                    }

                    if (a[lf] == 'S' && a[rg] == 'T')

                    {

                        vis[lf] = vis[rg] = 1;

                        --lf, ++rg;

                        ans -= 2;

                    }

                    else

                        break;

                }

                if (vis[rg]) lf = rg + 1, rg += 2;

                else lf = rg, ++rg;

            }

            else 

                ++lf, ++rg;

        }

        cout << ans << endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.189901254318533x):
#include <bits/stdc++.h>

using namespace std;



const int MAXN = 100005;

const int MOD = int(1e9) + 7;

const double PI = acos (-1.0);

const int INF = 0x3f3f3f3f;

const int dx[] = { -1, 0, 1, 0, 1, 1, -1, -1 };

const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };



template <class T> inline T min (T a, T b, T c) { return min (min (a, b), c); }

template <class T> inline T max (T a, T b, T c) { return max (max (a, b), c); }

template <class T> inline T min (T a, T b, T c, T d) { return min (min (a, b), min (c, d)); }

template <class T> inline T max (T a, T b, T c, T d) { return max (max (a, b), max (c, d)); }

template <class T> inline T min (T a, T b, T c, T d, T e) { return min (min (min (a, b), min (c, d)), e); }

template <class T> inline T max (T a, T b, T c, T d, T e) { return max (max (max (a, b), max (c, d)), e); }



string a;

stack<char> s;

int main ()

{

    cin >> a;

    int end = a.length();

    int ans = end;

    for(int i = 0; i < end; ++i)

    {

        if(!s.empty() && s.top() == 'S' && a[i] == 'T')

            ans -= 2, s.pop();

        else 

            s.push(a[i]);

    }

    cout << ans << endl;

    return 0;

}