#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}
void _cout() { cout << "\n"; }
template <class Head, class... Tail>
void _cout(Head&& head, Tail&&... tail) {
  cout << head;
  _cout(forward<Tail>(tail)...);
}
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
int main(void) {
  string s;
  _cin(s);
  int n = (int)s.size();
  int a = 0, ans = 0;
  for (int i = 0; i < (n); i++) {
    a += ((s[i] == 'S') ? 1 : -1);
    if (a < 0 && s[i] == 'T') ans += 2;
  }
  _cout(ans);
}
