program test
	implicit none
	integer :: a=0,b=0,c=0,k=0,ans=0
    read *,a,b,c,k
    if(k<=a) then
    	write (*,'(i0)') k
    else
    	ans=a-(k-a-b)
    	write (*,'(i0)') ans
    end if
end program test