
#
X = input()
len_X = len(X)

def find(c, i):
    j = i
    while j < len_X and X[j] == c:
        j += 1
    return min(j-i, len_X-i)

ans = 0
i = X.find('S')
while True:
    num_s = find('S', i)
    i += num_s
    if i == len_X:
        break

    num_t = find('T', i)
    i += num_t
    ans += min(num_s, num_t)
    # print(num_s, num_t)

    if i  == len_X:
        break


print(len_X - ans * 2)




