import Control.Monad main :: IO () main = do [n, _] <- map read . words <$> getLine :: IO [Int] as <- replicateM n getLine let ans = solve as print ans solve :: [String] -> Int solve as = solve_rec as 0 where solve_rec [] c = c solve_rec (a:as) c = solve_rec as (c + count a 'W') count a ch = count_rec a ch 0 count_rec [] _ n = n count_rec (a:s) ch n = count_rec s ch (n + if a == ch then 1 else 0)