def main():
  S = str(input())
  ans = 0
  num_s = 0
  flag = False
  for i in range(len(S)):
    if S[i] == 'S' and flag:
      num_s = 0
      flag = False
    if S[i] == 'S':
      num_s += 1
    if S[i] == 'T':
      flag = True
      if num_s > 0:
        ans += 2
        num_s-=1
  print(len(S)-ans)
  
if __name__ == "__main__":
  main()