A, B, C, D = map(int, input().split()) ans = 0 for i in range(min(A, D)+1): y = i*C if y>B: break x = i+y if x>D: break ans = i print(ans)