use std::io::{self, Read};

fn main() -> io::Result<()> {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer)?;
    buffer = buffer.trim_right().to_string();

    let mut spos = 0;
    let mut tpos = 0;
    let endpos = buffer.len();
    let mut count = 0;

    loop {
        if spos >= endpos - 1 {
            break
        }
        let buf = &buffer[spos..];
        //println!("buf={}", buf);
        match buf.find("ST") {
            Some(ofs) => {
                spos = spos + ofs;
                tpos = spos + 1;
            },
            None => {
                break
            },
        }
        //println!("found at {},{}", spos, tpos);
        count = count + 1;

        loop {
            if spos == 0 {
                break
            }
            if tpos + 1 >= endpos {
                break
            }
            spos = spos - 1;
            tpos = tpos + 1;
            let buf = buf.as_bytes();
            if buf[spos as usize] == b'S' && buf[tpos as usize] == b'T' {
                count = count + 1;
                //println!("found at {} {}", spos, tpos);
            } else {
                break
            }
        }
        spos = tpos
    }

    //println!("buf.len={}", buffer.len());
    println!("{}", buffer.len() - count * 2);
    Ok(())

} 
