function Main(input){
  input = input.split("\n")[0].split(" ");
  const A = parseInt(input[0],10);
  const B = parseInt(input[1],10);
  const C = parseInt(input[2],10);
  const D = parseInt(input[3],10);
  var ans;
  var max_AC;
  var min_BD;

  if(C >= B || D <= A){
    ans = 0;
  }else{
    max_AC = Math.max(A,C);
    min_BD = Math.min(B,D);
    ans = min_BD - max_AC;
  }
  console.log(ans);
}

const fs=require("fs");
Main(fs.readFileSync("/dev/stdin","utf-8"));
