#!/usr/bin/env python
# -*- coding:utf-8 -*-

x = input()
n = len(x)

i = 0
s = 0
t = 0
cnt = 0
while i < n:
    while i < n and x[i] == 'T':
        i += 1
        t += 1
    tmp = min(t, s)
    cnt += tmp * 2
    if t - tmp == 0:
        s -= tmp
    else:
        s = 0
        t = 0
    while i < n and x[i] == 'S':
        i += 1
        s += 1
print(n - cnt)
