-- Wrongri-La Shower {-# LANGUAGE Arrows #-} import Control.Arrow import Data.List main = do d <- readLn s <- getLine t <- getLine let u = (replicate 14 'x') ++ s ++ t ++ (replicate 14 'x') f (_:b@(m,'o'):c:ds) = max m $ f (b:c:ds) f ((l,_):b@(m,'x'):c@(n,_):ds) | m <= d = max (l+m+n) $ f (b:c:ds) | otherwise = maximum [d+l, d+n, f (b:c:ds)] f _ = 0 in print $ f $ ((0,'x'):).(++[(0,'x')]) $ map (length &&& head) $ group u