program abc107c
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,k,i,s
    integer(int32):: ans
    integer(int32), allocatable:: x(:)
    logical,allocatable:: passed(:)

    read*, n,k
    allocate(x(n))
    allocate(passed(n), source=.false.)
    read*, x(:)
    s=0
    do i=1,n-1
        if (x(i) <= 0 .and. 0 < x(i+1)) then
            s = i
            exit
        end if
    end do

    ans = 200000000
    if (s > 0) ans = min(ans, dfs(s,-x(s), passed,1))
    if (s < n) ans = min(ans, dfs(s+1, x(s+1), passed,1))

    print'(i0)', ans
    
contains
    recursive function dfs(nowind,nowtime,passed,arrive) result(ret)
        integer(int32):: nowind, nowtime,ret,arrive
        integer(int32):: i
        logical:: passed(n)
        logical:: nextpassed(n)
        ! print*, nowind, nowtime,arrive
        ret = 200000000
        if (arrive == k) then
            ret = min(ret, nowtime)
            return
        end if

        nextpassed(:) = passed(:)
        nextpassed(nowind) = .true.
        do i=nowind+1,n
            if (.not. nextpassed(i)) then
                ret = min(ret, dfs(i,nowtime+x(i)-x(nowind), nextpassed, arrive+1))
                exit
            end if
        end do
        do i=nowind-1,1,-1
            if (.not. nextpassed(i)) then
                ret = min(ret, dfs(i,nowtime+x(nowind)-x(i), nextpassed, arrive+1))
                exit
            end if
        end do
    end function
end program abc107c