function Main(input){
  
  input = input.split(" ");
  const A = parseInt(input[0],10);
  const B = parseInt(input[1],10);
  let K = parseInt(input[3],10);
  
  if( A + B >= K ){
  	console.log(A);
  }else{
  	K = K - A - B;
    console.log(A - K);
  }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));