X = input()
X_list = []
for i in range(len(X)):
    X_list.append(X[i])
n = 0
for i in X_list:
    if i == "S":
        break
    n += 1
count = n
m = 0
for i in range(len(X_list) - 1, 0, -1):
    if X_list[i] == "T":
        break
    m += 1
count += m
m - 1
cntS = 0
cntT = 0
for i in range(n, len(X_list) - m):
    if X_list[i] == "S":
        cntS += 1
    else:
        cntT += 1
print(len(X_list) - min([cntS, cntT]) * 2)
