#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  if (s.size() == 2) {
    if (s[0] == 'S' && s[1] == 'T')
      cout << 0;
    else
      cout << 1;
    return 0;
  }
  int ans = 0;
  int x = 0;
  while (x < n - 1) {
    while (x < n - 1 && (s[x] != 'S' && s[x + 1] != 'T')) {
      x++;
    }
    if (x >= n - 1) break;
    int y = x, z = x + 1;
    while (y >= 0 && s[y] == 'S') {
      y--;
    }
    while (z <= n - 1 && s[z] == 'T') {
      z++;
    }
    ans += 2 * min(x - y, z - x - 1);
    x = z;
  }
  cout << n - ans;
}
