"use strict";
    
const main = arg => {
    const times = arg.split("\n")[0].split(" ");
    
    /*
    if(times[2] > times[1]) {
        console.log(0);
        return;
    }
    
    const start = Math.max(times[0], times[2]);
    const end   = Math.min(times[1], times[3]);
    
    console.log(end - start > 0 ? end - start : 0);
    */
    
    console.log(Math.max(0, Math.min(times[1], times[3]) - Math.max(times[0], times[2])));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));