a, b, c, k = list(map(int, input().split()))

if k <= a:

    print(k)

elif k <= a + b:

    print(a)

else:

    print((a - (k - (a + b))))
a, b, c, k = list(map(int, input().split()))

print((k if k <= a else a if k <= a + b else a - (k - a - b)))
a, b, c, k = list(map(int, input().split()))
if k <= a:
    print(k)
elif k <= a + b:
    print(a)
else:
    print((a - (k - (a + b))))

a, b, c, k = list(map(int, input().split()))
print((k if k <= a else a if k <= a + b else a - (k - a - b)))

-if k <= a: -    print(k) -elif k <= a + b: -    print(a) -else: -    print((a - (k - (a + b)))) +print((k if k <= a else a if k <= a + b else a - (k - a - b)))