a = input().rstrip().split(' ')

A,B,C,K = int(a[0]),int(a[1]),int(a[2]),int(a[3])

s = 0



if K - A <= 0:

    print(K)

else:

    K -= A

    if K - B <= 0:

        print(A)

    else:

        K -= B

        print((A-K))
A,B,C,K = list(map(int,input().split()))



xa = min(K,A)

K -= xa

xb = min(K,B)

K -= xb





ans = xa - K

print(ans)
a = input().rstrip().split(" ")
A, B, C, K = int(a[0]), int(a[1]), int(a[2]), int(a[3])
s = 0
if K - A <= 0:
    print(K)
else:
    K -= A
    if K - B <= 0:
        print(A)
    else:
        K -= B
        print((A - K))

A, B, C, K = list(map(int, input().split()))
xa = min(K, A)
K -= xa
xb = min(K, B)
K -= xb
ans = xa - K
print(ans)

-a = input().rstrip().split(" ") -A, B, C, K = int(a[0]), int(a[1]), int(a[2]), int(a[3]) -s = 0 -if K - A <= 0: -    print(K) -else: -    K -= A -    if K - B <= 0: -        print(A) -    else: -        K -= B -        print((A - K)) +A, B, C, K = list(map(int, input().split())) +xa = min(K, A) +K -= xa +xb = min(K, B) +K -= xb +ans = xa - K +print(ans)