program sample
implicit none
integer(8) A,B,C,K,M
read(*,*) A,B,C,K
if (K-A>0) then
    M=A
    K=K-A
else
    M=K
    go to 10
end if
if (K-B>0) then
    K=K-B
else 
    go to 10
end if
M=M-K
10 continue
write(*,*) M
stop
end program sample