import sys





def main() -> None:

    x = next_str()

    s_cnt = 0

    ans = 0



    for v in x:

        if v == 'S':

            s_cnt += 1

        if v == 'T':

            if s_cnt == 0:

                ans += 1

            else:

                s_cnt -= 1



    ans += s_cnt

    print(ans)





def next_str() -> str:

    result = ""

    while True:

        tmp = sys.stdin.read(1)

        if tmp.strip() != "":

            result += tmp

        elif tmp != '\r':

            break

    return result





if __name__ == '__main__':

    main()
import sys





def main() -> None:

    x = eval(input())

    s_cnt = 0

    ans = 0



    for v in x:

        if v == 'S':

            s_cnt += 1

        if v == 'T':

            if s_cnt == 0:

                ans += 1

            else:

                s_cnt -= 1



    ans += s_cnt

    print(ans)





def next_str() -> str:

    result = ""

    while True:

        tmp = sys.stdin.read(1)

        if tmp.strip() != "":

            result += tmp

        elif tmp != '\r':

            break

    return result





if __name__ == '__main__':

    main()
import sys


def main() -> None:
    x = next_str()
    s_cnt = 0
    ans = 0
    for v in x:
        if v == "S":
            s_cnt += 1
        if v == "T":
            if s_cnt == 0:
                ans += 1
            else:
                s_cnt -= 1
    ans += s_cnt
    print(ans)


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != "\r":
            break
    return result


if __name__ == "__main__":
    main()

import sys


def main() -> None:
    x = eval(input())
    s_cnt = 0
    ans = 0
    for v in x:
        if v == "S":
            s_cnt += 1
        if v == "T":
            if s_cnt == 0:
                ans += 1
            else:
                s_cnt -= 1
    ans += s_cnt
    print(ans)


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != "\r":
            break
    return result


if __name__ == "__main__":
    main()

-    x = next_str() +    x = eval(input())