X = input()

t, s = 0, 0
flag_t, flag_s = True, True
for i in range(len(X)):

    if flag_t:
        if X[i] == 'T':
            t += 1
        else:
            flag_t = False

    if flag_s:
        if X[-(i+1)] == 'S':
            s += 1
        else:
            flag_s = False

    if flag_t==False and flag_s==False:
        break

print(max(t, s)*2)