import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    X = input()

    # TTT .... SS

    cnt_head_T = 0
    for x in X:
        if x == 'T':
            cnt_head_T += 1
        else:
            break

    cnt_tail_S = 0
    for x in X[::-1]:
        if x == 'S':
            cnt_tail_S += 1
        else:
            break

    if cnt_head_T == len(X):
        print(cnt_head_T)
    elif cnt_tail_S == len(X):
        print(cnt_tail_S)
    else:
        rest_T = len(X) // 2 - cnt_head_T
        rest_S = len(X) // 2 - cnt_tail_S
        rest_len = max(rest_T, rest_S) - min(rest_T, rest_S)
        print(cnt_head_T + rest_len + cnt_tail_S)


if __name__ == '__main__':
    main()
