#include<iostream>
#define MIN(a,b) (a)<(b)?(a):(b)
std::string s;
signed main(){std::cin>>s;int l(s.length()),t1(0),t2(0),ans(0);for(register int i(0);i<l;i++){s[i]==83?t1++:t2+=(t1>0),t1>=t2?ans+=MIN(t1,t2)<<1,t1-=MIN(t1,t2),t2=0:8;}return std::cout<<l-ans<<std::endl,0;}