# [[num of subsentence S, num of subsentence T], [,], ...]

x = input()

t_flag = 0
s_t_tmp_num = [0, 0]
s_t_num = []
for i in range(len(x)):
    if x[i] == "T":
        s_t_tmp_num[1] += 1
        t_flag = 1
    if x[i] == "S":
        if t_flag == 1:
            s_t_num.append(s_t_tmp_num)
            s_t_tmp_num = [0, 0]
            t_flag = 0
        s_t_tmp_num[0] += 1
s_t_num.append(s_t_tmp_num)
subt_num = 0

while True:
    for i in range(len(s_t_num) - 1, -1, -1):
        if s_t_num[i][0] >= 1 and s_t_num[i][1] >= 1:
            s_t_num[i][0], s_t_num[i][1] = s_t_num[i][0] - min(s_t_num[i]), s_t_num[i][1] - min(s_t_num[i])
        
        if i != 0 and s_t_num[i][0] == 0:
            s_t_num[i - 1][1] += s_t_num[i][1]
            s_t_num.pop(i)
    
        # print(s_t_num)

    if len(s_t_num) == 0:
        print(0)
        break
    elif len(s_t_num) == 1 and (s_t_num[0][0] == 0 or s_t_num[0][1] == 0):
        print(sum(s_t_num[0]))
        break
    elif len(s_t_num) == 2 and s_t_num[0][0] == 0 and s_t_num[1][1] == 0:
        print(sum(s_t_num[0]) + sum(s_t_num[1]))
        break
