function Main(input) {
input = input.split("\n");
var count =input[0];
const a = count.split(" ")[0];
const b = count.split(" ")[1];
const c = count.split(" ")[2];
const d = count.split(" ")[3];

const result1=Math.max(a,c)
const result2=Math.min(b,d)


const result=b-c-a;
if(result2<result1){
console.log(0);
}else{
    console.log(result2-result1);
}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));