import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import Data.Char

solve :: Int -> Int -> Int -> Int 
solve n k i = (loop 0 i (k-1)) + loop' (n-1) i (k-1)
    where
        loop s curr step
            | curr <= s = 0
            | otherwise = 1  + loop s (curr-step) step
        loop' g curr step
            | curr >= g = 0
            | otherwise = 1  + loop' g (curr+step) step
        

main = do
    [n,k] <- map read . words <$> getLine
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    let Just i = VU.elemIndex 1 xs
    print $ solve n k i