paramA, paramB, paramC, paramK = list([int(x) for x in input().split(' ')])



result = min(paramA, paramK)

paramK -= paramA

if paramK > 0:

    paramK -= paramB

    if paramK > 0:

        result -= min(paramC, paramK)



print(result)
paramA, paramB, paramC, paramK = list([int(x) for x in input().split(' ')])



result = min(paramA, paramK)

paramK -= paramA

paramK -= paramB

if paramK > 0:

    result -= min(paramC, paramK)



print(result)
paramA, paramB, paramC, paramK = list([int(x) for x in input().split(" ")])
result = min(paramA, paramK)
paramK -= paramA
if paramK > 0:
    paramK -= paramB
    if paramK > 0:
        result -= min(paramC, paramK)
print(result)

paramA, paramB, paramC, paramK = list([int(x) for x in input().split(" ")])
result = min(paramA, paramK)
paramK -= paramA
paramK -= paramB
if paramK > 0:
    result -= min(paramC, paramK)
print(result)

+paramK -= paramB -    paramK -= paramB -    if paramK > 0: -        result -= min(paramC, paramK) +    result -= min(paramC, paramK)