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

if K <= A:

    print(K)

    exit(0)

K -= A

ans = A

if K <= B:

    print(ans)

    exit(0)

K -= B

print((ans-K))

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

if K <= A:

    print(K)

    exit(0)

K -= A

if K <= B:

    print(A)

    exit(0)

print((A-(K-B)))

A, B, C, K = list(map(int, input().split()))
if K <= A:
    print(K)
    exit(0)
K -= A
ans = A
if K <= B:
    print(ans)
    exit(0)
K -= B
print((ans - K))

A, B, C, K = list(map(int, input().split()))
if K <= A:
    print(K)
    exit(0)
K -= A
if K <= B:
    print(A)
    exit(0)
print((A - (K - B)))

-ans = A -    print(ans) +    print(A) -K -= B -print((ans - K)) +print((A - (K - B)))