#include<stdio.h>

void main(void)
{
  long int a,b,c,k;
  long int result=0;
  scanf("%ld %ld %ld %ld",&a,&b,&c,&k);
  if(a>=k){
    result=a;
  }else if(a<k&&(a+b)>k){
    result=a;
  }else{
    result=0;
  }
  printf("%ld\n",result);
}
