import sys

sys.setrecursionlimit(10 ** 9)

# input = sys.stdin.readline    ####

def int1(x): return int(x) - 1

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

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

def MI1(): return list(map(int1, input().split()))

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

def LI1(): return list(map(int1, input().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]

def MS(): return input().split()

def LS(): return list(eval(input()))

def LLS(rows_number): return [LS() for _ in range(rows_number)]

def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))

INF = float('inf')

# from math import ceil, floor, log2

from collections import deque, defaultdict

# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations

# from heapq import heapify, heappop, heappush

# import numpy as np    # cumsum

# from bisect import bisect_left, bisect_right



def solve():

    X = eval(input())

    # print(X)



    L = deque([])

    R = deque(list(X))

    # for _ in range(100):

    while R:

        if not L:

            L.append(R.popleft())

            continue



        pre = L.pop()

        now = R.popleft()

        if pre == 'S' and now == 'T':

            pass

        else:

            L.append(pre)

            L.append(now)

    print((len(L)))





if __name__ == '__main__':

    solve()



import sys

sys.setrecursionlimit(10 ** 9)

# input = sys.stdin.readline    ####

def int1(x): return int(x) - 1

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

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

def MI1(): return list(map(int1, input().split()))

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

def LI1(): return list(map(int1, input().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]

def MS(): return input().split()

def LS(): return list(eval(input()))

def LLS(rows_number): return [LS() for _ in range(rows_number)]

def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))

INF = float('inf')

# from math import ceil, floor, log2

from collections import deque, defaultdict

# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations

# from heapq import heapify, heappop, heappush

# import numpy as np    # cumsum

# from bisect import bisect_left, bisect_right



def solve():

    X = eval(input())

    # print(X)



    L = deque([])

    for now in X:

        if not L:

            L.append(now)

            continue



        if now == 'T':

            pre = L.pop()

            if pre == 'S':

                continue

            else:

                L.append(pre)

        L.append(now)



    print((len(L)))





if __name__ == '__main__':

    solve()



import sys

sys.setrecursionlimit(10**9)
# input = sys.stdin.readline    ####
def int1(x):
    return int(x) - 1


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


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


def MI1():
    return list(map(int1, input().split()))


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


def LI1():
    return list(map(int1, input().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


def MS():
    return input().split()


def LS():
    return list(eval(input()))


def LLS(rows_number):
    return [LS() for _ in range(rows_number)]


def printlist(lst, k=" "):
    print((k.join(list(map(str, lst)))))


INF = float("inf")
# from math import ceil, floor, log2
from collections import deque, defaultdict

# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right
def solve():
    X = eval(input())
    # print(X)
    L = deque([])
    R = deque(list(X))
    # for _ in range(100):
    while R:
        if not L:
            L.append(R.popleft())
            continue
        pre = L.pop()
        now = R.popleft()
        if pre == "S" and now == "T":
            pass
        else:
            L.append(pre)
            L.append(now)
    print((len(L)))


if __name__ == "__main__":
    solve()

import sys

sys.setrecursionlimit(10**9)
# input = sys.stdin.readline    ####
def int1(x):
    return int(x) - 1


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


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


def MI1():
    return list(map(int1, input().split()))


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


def LI1():
    return list(map(int1, input().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


def MS():
    return input().split()


def LS():
    return list(eval(input()))


def LLS(rows_number):
    return [LS() for _ in range(rows_number)]


def printlist(lst, k=" "):
    print((k.join(list(map(str, lst)))))


INF = float("inf")
# from math import ceil, floor, log2
from collections import deque, defaultdict

# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right
def solve():
    X = eval(input())
    # print(X)
    L = deque([])
    for now in X:
        if not L:
            L.append(now)
            continue
        if now == "T":
            pre = L.pop()
            if pre == "S":
                continue
            else:
                L.append(pre)
        L.append(now)
    print((len(L)))


if __name__ == "__main__":
    solve()

-    R = deque(list(X)) -    # for _ in range(100): -    while R: +    for now in X: -            L.append(R.popleft()) +            L.append(now) -        pre = L.pop() -        now = R.popleft() -        if pre == "S" and now == "T": -            pass -        else: -            L.append(pre) -            L.append(now) +        if now == "T": +            pre = L.pop() +            if pre == "S": +                continue +            else: +                L.append(pre) +        L.append(now)