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