#include <stack>
#include <cstdio>
#include <vector>
char x[1<<19];
int solve(void) {
    std::stack<char> st;
    int len = strlen(x);
    for(int i = 0; i < len; i++) {
        if(x[i] == 'S') st.push(x[i]);
        else if(x[i] == 'T' && (st.empty() || st.top() == 'T') st.push(x[i]);
        else st.pop();
    }
    return st.size();
}
int main(void) {
    fgets(x, 1 << 19, stdin);
    printf("%d", solve());
    return 0;
}