function main(input) {
  var a = Math.max(input[0].split(" ")[0]-0, input[0].split(" ")[2]-0);
  var b = Math.min(input[0].split(" ")[1]-0, input[0].split(" ")[3]-0);
  console.log(Math.max(b-a,0));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
