import math

import copy

from operator import mul

from functools import reduce

from collections import defaultdict

from collections import Counter

from collections import deque

# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)

from itertools import product

# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)

from itertools import permutations

# 組み合わせ {}_len(seq) C_n: combinations(seq, n)

from itertools import combinations

# 一次元累積和

from itertools import accumulate

from bisect import bisect_left, bisect_right



# import numpy as np

# from scipy.special import perm

# from scipy.special import comb



def inside(y, x, H, W):

    return 0 <= y < H and 0 <= x < W



# 四方向: 右, 下, 左, 上

dy = [0, -1, 0, 1]

dx = [1, 0, -1, 0]

 

def i_inpl(): return int(eval(input()))

def l_inpl(): return list(map(int, input().split()))

INF = float("inf")



########

X = eval(input())



cnt = 0

sum_cnt = 0

for xi in X:

    if xi == "S":

        cnt += 1

    else:

        if cnt > 0:

            cnt -= 1

            sum_cnt += 1



print((len(X) - sum_cnt*2))
import math

import copy

from operator import mul

from functools import reduce

from collections import defaultdict

from collections import Counter

from collections import deque

# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)

from itertools import product

# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)

from itertools import permutations

# 組み合わせ {}_len(seq) C_n: combinations(seq, n)

from itertools import combinations

# 一次元累積和

from itertools import accumulate

from bisect import bisect_left, bisect_right



import re

# import numpy as np

# from scipy.misc import perm

# from scipy.misc import comb



def inside(y, x, H, W):

    return 0 <= y < H and 0 <= x < W



# 四方向: 右, 下, 左, 上

dy = [0, -1, 0, 1]

dx = [1, 0, -1, 0]

 

def i_inpl(): return int(eval(input()))

def l_inpl(): return list(map(int, input().split()))

def line_inpl(x): return [i_inpl() for _ in range(x)]



INF = int(1e18)

MOD = int(1e9)+7 # 10^9 + 7



########



X = eval(input())



t_cnt, s_cnt = 0, 0

for Xi in X:

    if Xi == "S":

        s_cnt += 1

    elif Xi == "T":

        if s_cnt > 0:

            s_cnt -= 1

        else:

            t_cnt += 1



print((t_cnt + s_cnt))
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product

# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations

# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations

# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb
def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def i_inpl():
    return int(eval(input()))


def l_inpl():
    return list(map(int, input().split()))


INF = float("inf")
########
X = eval(input())
cnt = 0
sum_cnt = 0
for xi in X:
    if xi == "S":
        cnt += 1
    else:
        if cnt > 0:
            cnt -= 1
            sum_cnt += 1
print((len(X) - sum_cnt * 2))

import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product

# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations

# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations

# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right
import re

# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb
def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def i_inpl():
    return int(eval(input()))


def l_inpl():
    return list(map(int, input().split()))


def line_inpl(x):
    return [i_inpl() for _ in range(x)]


INF = int(1e18)
MOD = int(1e9) + 7  # 10^9 + 7
########
X = eval(input())
t_cnt, s_cnt = 0, 0
for Xi in X:
    if Xi == "S":
        s_cnt += 1
    elif Xi == "T":
        if s_cnt > 0:
            s_cnt -= 1
        else:
            t_cnt += 1
print((t_cnt + s_cnt))

+import re -# from scipy.special import perm -# from scipy.special import comb +# from scipy.misc import perm +# from scipy.misc import comb -INF = float("inf") +def line_inpl(x): +    return [i_inpl() for _ in range(x)] + + +INF = int(1e18) +MOD = int(1e9) + 7  # 10^9 + 7 -cnt = 0 -sum_cnt = 0 -for xi in X: -    if xi == "S": -        cnt += 1 -    else: -        if cnt > 0: -            cnt -= 1 -            sum_cnt += 1 -print((len(X) - sum_cnt * 2)) +t_cnt, s_cnt = 0, 0 +for Xi in X: +    if Xi == "S": +        s_cnt += 1 +    elif Xi == "T": +        if s_cnt > 0: +            s_cnt -= 1 +        else: +            t_cnt += 1 +print((t_cnt + s_cnt))