use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.input()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let s: String = sc.input();
    let mut s: Vec<char> = s.chars().collect();

    let n = s.len();
    s.push('S');
    let mut s_cnt = 0;
    let mut t_cnt = 0;
    let mut ans = 0;
    for i in 0..n {
        if s[i] == 'T' {
            t_cnt += 1;
            if s[i + 1] == 'S' {
                ans += std::cmp::min(t_cnt, s_cnt);
                t_cnt = 0;
                s_cnt = 0;
            }
        } else {
            s_cnt += 1;
        }
    }

    println!("{}", n - ans * 2);
}
