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

if k<=a:

    print(k)

elif a < k and k <= a+b:

    print(a)

elif k > a+b:

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

A = min(a,k)

k -= A

B = min(b,k)

k -= B

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

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

-if k <= a: -    print(k) -elif a < k and k <= a + b: -    print(a) -elif k > a + b: -    print((a - (k - a - b))) +A = min(a, k) +k -= A +B = min(b, k) +k -= B +print((A - k))