program prob5
    implicit none
    integer :: K, T
    integer, allocatable, dimension(:) :: a
    integer :: m
    read(*,*) K, T  
    allocate(a(T))
    read(*,*) a
    m = maxval(a)
    if(mod(K, 2) == 0) then
        write(*,*) max(0,(m - K/2)*2-1)
    else
        write(*,*) max(0,(m - K/2)*2-2)
    end if

    deallocate(a)

    stop
contains
end program prob5