#include <iostream>
#include <vector>
using namespace std;

vector<char>stack;
// stack.back() will bring you to the last index

void checkForT(string s , char character, int index){
	if(!stack.empty() && stack.back()!= 'S'){
		stack.push_back(character);
	}
	else if(!stack.empty()){
		stack.pop_back();
	}
	else if(stack.empty()){
		stack.push_back(character);
	}
}

void checkForS(string s , char character, int index){
	stack.push_back(character);
}

int main(){
	string s;
	cin >> s; 

	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'S'){
			checkForS(s , s[i] , i);
		}
		else{ // else if stack[i]=='T'
			checkForT(s, s[i] , i);
		}
	}
	cout << stack.size() << endl; // Amount of elements left in stack
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;

int main()
{
    string x;
    cin >> x;
    int stack = 0, puyo = 0;
    rep(i, x.length())
    {
        if (x[i] == 'S')
            stack++;
        else if (stack)
        {
            stack--;
            puyo++;
        }
    }
    cout << x.length() - 2 * puyo << endl;
}