#from statistics import median

#import collections

#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]

from fractions import gcd

from itertools import combinations,permutations,accumulate # (string,3) 3回

#from collections import deque

from collections import deque,defaultdict,Counter

#import bisect

#

#    d = m - k[i] - k[j]

#    if kk[bisect.bisect_right(kk,d) - 1] == d:

#

#

#

# pythonで無理なときは、pypyでやると正解するかも！！

#

#



import sys

sys.setrecursionlimit(10000000)

mod = 10**9 + 7

#mod = 9982443453

def readInts():

  return list(map(int,input().split()))

def I():

  return int(eval(input()))

X = eval(input())

sc = 0

cnt = 0

ln = len(X)

for i in range(ln):

    if X[i] == 'S':

        sc += 1

    if X[i] == 'T':

        if sc >= 1:

            sc -= 1

            cnt += 1

print((ln - cnt * 2))

#from statistics import median

#import collections

#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]

from fractions import gcd

from itertools import combinations,permutations,accumulate, product # (string,3) 3回

#from collections import deque

from collections import deque,defaultdict,Counter

import decimal

import re

#import bisect

#

#    d = m - k[i] - k[j]

#    if kk[bisect.bisect_right(kk,d) - 1] == d:

#

#

#

# pythonで無理なときは、pypyでやると正解するかも！！

#

#

# my_round_int = lambda x:np.round((x*2 + 1)//2)

# 四捨五入g

import sys

sys.setrecursionlimit(10000000)

#mod = 10**9 + 7

#mod = 9982443453

mod = 998244353

def readInts():

  return list(map(int,input().split()))

def I():

  return int(eval(input()))

s = eval(input())

sc = 0

ans = 0

for i in range(len(s)):

    if s[i] == 'S':

        sc += 1

    else:

        if sc:

            sc -= 1

            ans += 1

print((len(s) - ans*2))

# from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate  # (string,3) 3回

# from collections import deque
from collections import deque, defaultdict, Counter

# import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
import sys

sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
    return list(map(int, input().split()))


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


X = eval(input())
sc = 0
cnt = 0
ln = len(X)
for i in range(ln):
    if X[i] == "S":
        sc += 1
    if X[i] == "T":
        if sc >= 1:
            sc -= 1
            cnt += 1
print((ln - cnt * 2))

# from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate, product  # (string,3) 3回

# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re

# import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys

sys.setrecursionlimit(10000000)
# mod = 10**9 + 7
# mod = 9982443453
mod = 998244353


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


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


s = eval(input())
sc = 0
ans = 0
for i in range(len(s)):
    if s[i] == "S":
        sc += 1
    else:
        if sc:
            sc -= 1
            ans += 1
print((len(s) - ans * 2))

-from itertools import combinations, permutations, accumulate  # (string,3) 3回 +from itertools import combinations, permutations, accumulate, product  # (string,3) 3回 +import decimal +import re +# my_round_int = lambda x:np.round((x*2 + 1)//2) +# 四捨五入g -mod = 10**9 + 7 +# mod = 10**9 + 7 +mod = 998244353 + + -X = eval(input()) +s = eval(input()) -cnt = 0 -ln = len(X) -for i in range(ln): -    if X[i] == "S": +ans = 0 +for i in range(len(s)): +    if s[i] == "S": -    if X[i] == "T": -        if sc >= 1: +    else: +        if sc: -            cnt += 1 -print((ln - cnt * 2)) +            ans += 1 +print((len(s) - ans * 2))