import Data.List
import Data.Maybe
main :: IO ()
main = do
  _ <- readLn :: IO Int
  xs <- getLine :: IO String    
  let ns = [num | d <- xs, let ind = d `elemIndex` xs, let num = (length $ filter (/=d) $ take (fromJust ind) xs) - 1 + (length $ filter (==d) $ tail (drop (fromJust ind) xs))]
  print $ minimum ns

  

