#include <iostream>
#include <cstdio>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <fstream>
#include <memory.h>
#include <iomanip>
#include <omp.h>
#include <bitset>
#include <string>
#include <list>

using namespace std;

#define right asfdsg
#define left asfdsvs
#define MAXN 1000000000
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define x1 asicvlid
#define y1 ascnsdkn

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

char s[200500];
int pred[200500];
int nxt[200500];
int n;

int getPred(int p) {
    return pred[p] == p ? p : pred[p] = getPred(pred[p]);
}

int getNext(int p) {
    return nxt[p] == p ? p : nxt[p] = getNext(nxt[p]);
}

int main() {
    scanf ("%s", s + 1);
    n = strlen(s + 1);
    for (int i = 1; i <= n + 1; i ++) pred[i] = i, nxt[i] = i;
    int b = 1;
    int e = 2;
    int cnt = 0;
    while ( e <= n ) {
        if (s[b] == 'S' && s[e] == 'T') {
            pred[b] = getPred(b - 1);
            nxt[e] = getNext(e + 1);
            b = pred[b];
            e = nxt[e];
            cnt += 2;
            if (b == 0) {
                b = e;
                e = getNext(e + 1);
            }
        } else {
            b = getNext(b + 1);
            e = getNext(e + 1);
        }
    }
    cout << n - cnt;
    return 0;
}
