A,B,C,D=map(int,input().split()) num=-1 for i in range(A+1): b=i*C if b<=B and b+i<=D: num=max(i,num) print(num)