#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  string X;
  cin >> X;
  int X_size = X.size();
  int delete_num = 0;
  int S_left_num = 0;
  for (int i = 0; i < X_size; i++) {
    if (X[i] == 'S')
      S_left_num++;
    else {
      if (S_left_num) {
        S_left_num--;
        delete_num += 2;
      }
    }
  }
  cout << X_size - delete_num << endl;
  return 0;
}
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int tmp=a.find("ST");
	while(a.length()>0&&tmp>=0)
	{
		a.erase(tmp,2);
		int x=max(tmp-1,0);
		tmp=a.find("ST",x);
		if(tmp==string::npos&&(a[tmp]!='S'||a[tmp+1]!='T'))
			tmp=-1;
	}
	cout<<a.length()<<endl;
	return 0;
} 