#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <cassert>
#include <unordered_map>
#include <regex>
#include <stdio.h>
#include <fstream>
using namespace std;
#define ll long long int
const int N = 400006;
#define lson l,mid,rt<<1
#define eps 1e-9
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define oo 1e18
#define noo INT_MIN
//if ( a > b || a > j || b < i ) {
//return ( ( sum ) { 0, 0 } );
//if ( a >= i && b <= j ) {
//return tree[ node ]
inline int scan(){
    char c = getchar();
    int x = 0;
    while(c<'0'||c>'9'){
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+c-'0';
        c=getchar();
    }
    return x;
}
//const int inf = 1 << 29;
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
#define OUT_RT cerr << (float(clock()) / CLOCKS_PER_SEC) << endl
#define ios ios_base::sync_with_stdio(false);cin.tie(0)
ll add(ll a, ll b){
    return a+b-(a+b>=mod)*mod;
}
ll sub(ll a, ll b){
    return a-b+(a-b<0)*mod;
}
inline ll gcd(ll a, ll b){
    ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a;
}
const int sievesize = (ll)1e6+10;
bool prime[sievesize+1];
void sieve(){
    ll x,y; prime[0]=prime[1]=true; for(x=2;x*x<=sievesize;x++){ if(!prime[x]) for(y=x*x;y<=sievesize;y+=x) prime[y]=true; }
    /*char str[10000009]={};
        int p=10000001,j,i;
        int sqr=sqrt(p);
        for(i=2; i<=sqr; i++)
        {
            if(str[i]==0)
            {
                for(j=i; j<=(p/i); j++)
                    str[i*j]=1;
            }
        }
    */
}
ll nextPowerOf2(ll n){
    n--;n |= n >> 1;n |= n >> 2;n |= n >> 4;n |= n >> 8;n |= n >> 16;n++;return n;
}
bool isPerfectSquare(ll n){
    if (n < 0)return false;ll tst = (ll)(sqrt(n) + 0.5);return tst*tst == n;
}
bool triangle(ll a, ll b, ll c){
    return ((a+b)>c&&(b+c)>a&&(a+c)>b);
}
ll chartoint(char c){
    switch(c){case '1':return 1;break;case '2':return 2;break;case '3':return 3;break;case '4':return 4;break;case '5':return 5;break;case '6':return 6;break;case '7':return 7;break;case '8':return 8;break;case '9':return 9;break;default: return 0;break;}
}
ll isnum(char s){
    if(s=='1'||s=='2'||s=='3'||s=='4'||s=='5'||s=='6'||s=='7'||s=='8'||s=='9'||s=='0') return 1; return 0;
}
bool isvowel(char c){
    return(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U'||c=='Y'||c=='y');
}
//std::bitset<8> foo (std::string("10110011"));
//int dx[] = {1, -1, 0, 0};
//int dy[] = {0, 0, 1, -1};
//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*night move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*night move*/
//int x=(n & -n);
//int x=pow(2,floor(log(n)/log(2)));
// (val & (val - 1)) == 0 - - > check for power of two
//freopen ("/Users/priya/Desktop/B-small-attempt1.in","r",stdin);
//freopen ("/Users/priya/Desktop/B-small-attempt1.out","w",stdout);
string s;
stack< char > st;
ll op = 0;
int main(){
    cin >> s;
    for(ll i = 0; i < s.length(); i ++){
        if(st.empty()) st.push(s[i]);
        else{
            if(s[i] == 'T'){
                if(st.top() == 'S'){
                    st.pop();
                    op ++;
                }
                else st.push(s[i]);
            }
            else st.push(s[i]);
        }
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 644