#include<stdio.h>
void main()
{long long int a,b,c,k;
 printf("enter the values of A,B, C and K respectively");
  scanf("%lld",&a );
   scanf("%lld",&b);
   scanf("%lld",&c);
   scanf("%lld",&k);
 if( a>=k)
   printf("%lld",k);
 if(k>a && k<=(a+b))
   printf("%lld",a);
   if(k>(a+b))
     printf("%lld",(a-(k-a-b)));
}
