A,B,C,D =map(int,input().split()) if B/C >=A and A+B<=D: ans = A elif B/C < A and B/C>=1 and int(B/C)+B=1 and int(B/C)+B>D: ans=D/(C+1) else: ans=0 print(int(ans))