A, B, C, D = map(int, input().split()) total = 0 res = 0 while total + C + 1 <= D and B >= C and A > 0 and B > 0: #print(res, total, A, B) res += 1 total += 1 + C A -= 1 B -= C #print(res, total, A, B) print(res)