import sys
import string
import re
input = lambda: sys.stdin.readline()

st = []
X = input()
for x in X:
    if not len(st) == 0:
        top = st.pop()
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)
print(len(st))


# st = []
# s = input()
#
# for x in s:
#     if not len(st) == 0:
#         top = st.pop()
#         # print(top)
#         if top == "S" and x == "T":
#             continue
#         else:
#             st.append(top)
#             st.append(x)
#     else:
#         st.append(x)
#
# print(len(st))

# def main(s):
#     return s.replace("ST","")
#
# if __name__ == '__main__':
#     cnt  = 0
#     s = input()
#     k = ""
#     flag = False
#     s= main(s)
#     cnt = s.count("ST")
#     if cnt != 0:
#         s = main(s)
#         print(len(s) - 1)
#     else:
#         # print(0)
#         print(len(s) - 1)
