from collections import *



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()))



if K<A:

    print(K)

elif K<A+B:

    print(A)

else:

    print((A-(K-A-B)))
from collections import *

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()))
if K < A:
    print(K)
elif K < A + B:
    print(A)
else:
    print((A - (K - A - B)))

-from collections import * - -if K <= A: +if K < A: -elif K <= A + B: +elif K < A + B: