function Main(input) {
    var input = input.split(' ').map(n => parseInt(n, 10));
    var A = input[0];
    var B = input[1];
    var C = input[2];
    var D = input[3];
    if(Math.max(A, C) <= Math.min(B, D)) {
     console.log(Math.min(B, D) - Math.max(A, C)); 
    } else{
        console.log(0);
    }
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));