-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE BangPatterns #-}
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS
import qualified Data.Sequence as Seq
import Data.Foldable (or)
import qualified Test.QuickCheck as QC

naive :: U.Vector Bool -> Int
naive v = let s0 = Seq.fromFunction (U.length v) (v U.!)
          in loop 0 [s0]
  where
    loop !i ss = case concat <$> mapM oneStep ss of
                   Nothing -> i
                   Just ss' -> loop (i+1) ss'

oneStep :: Seq.Seq Bool -> Maybe [Seq.Seq Bool]
oneStep s = let (s0,s1') = Seq.spanl not s
                (s2,s1) = Seq.spanr id s1'
            in if Seq.null s1 then
                 Nothing
               else
                 Just $ [ Seq.update j True $ Seq.update i False s1
                        | i <- Seq.elemIndicesL True s1
                        , j <- Seq.elemIndicesR False s1
                        ] ++
                        [ Seq.update i False s1
                        | i <- Seq.elemIndicesL True s1
                        ] ++
                        [ Seq.update j True s1
                        | j <- Seq.elemIndicesR False s1
                        ]

solve :: U.Vector Bool -> Int
solve xs = let ys0 = U.scanl' (\acc t -> if t then acc + 1 else acc) 0 xs
               ys1 = U.scanr' (\t acc -> if t then acc else acc + 1) 0 xs
               ys = U.zipWith max ys0 ys1
           in U.minimum ys

main = do
  n <- readLn @Int
  s <- BS.getLine -- 'R' or 'W'
  -- 操作後： replicate k 'R' ++ replicate (n - k) 'W' for some k
  let v = U.generate n (\i -> s `BS.index` i == 'W')
  print $ solve v

check :: [Bool] -> Bool
check xs = let v = U.fromList xs in solve v == naive v

runTest :: IO ()
runTest = QC.quickCheckWith (QC.stdArgs { QC.maxSize = 15 })  check
