A,B,C,D=map(int,input().split()) ans = 0 for a in range(A+1): b = C*a if b <= B and a + b <= D: ans = a print(ans)