#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use List::Util qw( max );

my $string = <>;
chomp $string;

my $count = 0;
foreach my $c (split //, $string)
{
    if ($c eq 'T')
    {
        $count++;
    }
    else
    {
        last;
    }
}

my $count2 = 0;
foreach my $c (split //, reverse($string))
{
    if ($c eq 'S')
    {
        $count2++;
    }
    else
    {
        last;
    }
}
#print reverse($string);
#print " $count $count2\n";
print max($count, $count2) * 2;
