#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 public:
  vector<int> Parent;
  UnionFind(int N) { Parent = vector<int>(N, -1); }
  int root(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  int size(int A) { return -Parent[root(A)]; }
  bool connect(int A, int B) {
    A = root(A);
    B = root(B);
    if (A == B) {
      return false;
    }
    if (size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
};
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
long long extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
bool check(long long int a, long long int b) { return a > b; }
int main() {
  string s;
  cin >> s;
  int cntt = 0, cnts = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'S') {
      if (cntt == 0) {
        break;
      }
      cnts++;
    }
    if (s[i] == 'T') {
      if (cnts == 0) {
        cntt++;
      } else {
        cnts--;
      }
    }
  }
  cout << cntt * 2 << endl;
  return 0;
}
