A, B, C, D = map(int, input().split()) if D <= C or B < C: print(0) else: ans = 0 emax = 0 for i in range(D): ans += 1 A -= 1 B -= C emax += (1 + C) if A == 0 or B == 0: break elif emax > D: ans -= 1 break print(ans)