let
  X = readLine stdin
var
  cnt, s_cnt, t_cnt = 0

for i, v in X:
  if s_cnt == 0 and v == 'T':
    cnt += 1
    t_cnt = 0

  if v == 'S':
    s_cnt += 1
  if v == 'T':
    t_cnt += 1

  if t_cnt == s_cnt:
    s_cnt = 0
    t_cnt = 0

echo cnt + s_cnt - t_cnt
