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



if a >= k:

    print(k)

elif a + b >= k:

    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)

elif k > a+b:

    print((a- (k-(a+b))))
a, b, c, k = list(map(int, input().split()))
if a >= k:
    print(k)
elif a + b >= k:
    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)
elif k > a + b:
    print((a - (k - (a + b))))

-if a >= k: +if k <= a: -elif a + b >= k: +elif k <= a + b: -else: +elif k > a + b: