#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    string str;
    cin >> str;
    stack<char> stack;
    for(int i = 0; i < str.length(); i++) {
        char ch = str[i];
        switch(ch) {
            case 'S':
                stack.push('S');
                break;
            case 'T':
                if((!stack.empty()) && stack.top() == 'S') {
                    stack.pop();
                } else {
                    stack.push('T');
                }
                break;
            default:
                break;
        }
        debug("size: %ld\n", stack.size());
    }
    cout << stack.size() << endl;
    return 0;
}
#include <iostream>
#include <cstring>
#include <stack>
using namespace std;

stack<char> stacky;

int solve(string X, int N, int ans) {
      for(int i=0; i<N; i++) {
            if(X[i] == 'S') stacky.push('S');
            else {      // encounter 't'
                  if(!stacky.empty()) stacky.pop(); 
                  else ans++;
            }
      }
      ans += stacky.size();
      return ans;
}

int main() {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);

      string X;
      cin >> X;
      int N = X.size();
      
      cout << solve(X, N, 0) << endl;
}