import Control.Monad
import Text.Printf
import Control.Applicative

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO()
main = do
  [n] <- map read . words <$> getLine
  m <- replicateM n getInts
  printf "%s" $ slv n (concat m)

slv :: Int -> [Int] -> String
slv n vals = show $ min lNum rNum
  where lNum = search vals (0, 0)
        rNum = search (reverse (map (\x -> abs (x - n - 1)) vals)) (0, 0)

search :: [Int] -> (Int, Int) -> Int
search [] (_, val) = val
search (v:vs) (maxv, val) | v > maxv = search vs (v, val)
                          | otherwise = search vs (maxv, max val v)
