#include <bits/stdc++.h>
const long long int mxn = 1e5 + 7;
const long long int mod = 1e9 + 7;
const long long int inf = 1e18 + 9;
using namespace std;
long long int n, a[mxn], dp[1001][1001], p1, p2, cnt = 1;
string second;
int main() {
  cin >> second;
  for (int i = 0; i < second.size(); i++) {
    dp[i][i] = 1;
  }
  for (int l = 2; l <= second.size(); l++) {
    for (int i = 0; i < second.size() - l + 1; i++) {
      long long int j = i + l - 1;
      if (second[i] == 'S' && second[j] == 'T' && l == 2) {
        dp[i][j] = 0;
      } else if (second[i] == 'S' && second[j] == 'T') {
        if (!dp[i + 1][j - 1]) {
          dp[i][j] = dp[i + 1][j - 1];
        } else {
          dp[i][j] = inf;
          for (int x = i; x < j; x++) {
            dp[i][j] = min(dp[i][j], dp[i][x] + dp[x + 1][j]);
          }
        }
      } else {
        dp[i][j] = inf;
        for (int x = i; x < j; x++) {
          dp[i][j] = min(dp[i][j], dp[i][x] + dp[x + 1][j]);
        }
      }
    }
  }
  cout << dp[0][second.size() - 1];
  return 0;
}
