program answer
  implicit none

  integer :: K, T, i, j, ss, c, p, g
  integer, allocatable :: a(:)
  read(*,*) K, T
  allocate(a(T))
  read(*,*) a

  do i = 1, K-1
     do j = 1, K-1
        if(a(i)>a(j)) then
           ss=a(i)
           a(i)=a(i+1)
           a(i+1)=ss
        end if
     end do
  end do
  
  do
     if(sum(a)-maxval(a)==0) then
        write(*,*) maxval(a)-1
        exit
     end if

     do i = 1, K
        if(a(i)==maxval(a)) then
           c=i
           exit
        end if
     end do
     p=maxval(a)
     a(c)=p-1

     p=a(1)
     do i = 1, K
        if(i==c) then
           cycle
        end if
        if(a(i)>p) then
           p=a(i)
           g=i
        end if
     end do
     a(g)=p-1
  end do

  stop
 end program answer