program pr5
  implicit none
  integer, allocatable :: a(:)
  integer :: k, t
  integer :: i, ans
  read(*,*) k, t
  allocate(a(t))
  read(*,*) a

  if ( maxval(a) > sum(a) - maxval(a) + 1 ) then
     ans = maxval(a) - (sum(a) - maxval(a)) - 1
  else if ( t == 1 ) then
     ans = k - 1
  else
     ans = 0
  end if

  write(*,'(i0)') ans
  
  stop
end program pr5
