#include <iostream>
#include <string>
using namespace std;
int main() {
	string h;
	cin >> h;
	int t = 0, s = 0;
	for (int i = 0; i < h.length(); ++i) {
		if (h[i] == 'T') {
			if (s == 0) ++t;
			else --s;
		}
		else {
			++s;
		}
	}
	cout << t * 2 << endl;
}