function main(input) {
  const args = input.split(' ').map(n => parseInt(n, 10));
  
  const A = args[0];
  const B = args[1];
  const C = args[2];
  const D = args[3];
  
  if (Math.max(A, C) > Math.min(B,D)) {
    console.log(0);
  } else {
    console.log(Math.min(B, D) - Math.max(A, C));
  }
}

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