function main(input) {
	input =  input.split(" ").map(Number);
	const A = input[0];
	const B = input[1];
	const K = input[3];

	if ((A+B)>=K){
	    console.log(A);
	} else {
	    console.log(2*A+B-K);
	}

}


main(require("fs").readFileSync("/dev/stdin", "utf8").trim());