f :: String->Int->[Int]
f [] _=[]
f (x:xs) c1= if x=='W' then c1 : f xs (c1+1) else c1 : f xs c1

f2 :: String->Int->[Int]
f2 [] _=[]
f2 (x:xs) c1= if x=='E' then c1 : f2 xs (c1+1) else c1 : f2 xs c1

main =do
        e<-getLine
        e2<-getLine
        let z1= f e2 0
            z2= reverse (f2 (reverse e2) 0)
        putStrLn $ show $ minimum $ map (\(a,b)->a+b) $ zip  z1 z2