#include<stdio.h>

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