process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var abck = lines[0].split(' ');
 var a = Number(abck[0]);
 var b = Number(abck[1]);
 var c = Number(abck[2]);
 var k = Number(abck[3]);
 var ans = 0;

 ans = a*1 + c*(-1);

 var dis = a+b+c-k;

 ans = ans + dis;

 console.log(ans);
});