#include<stdio.h>
int main()
{
    int a,b,c,k,sum;
    printf("Enter 4 numbers:\n");
    scanf("%d %d %d %d",&a,&b,&c,&k);
    sum=a*1;
    if(k>a)
    {
        k=k-a-b;
        if(k>0)
        {
           sum+=k*-1;
        }
    }
    printf("%d\n",sum);
    return 0;
}
