"use strict"

function main(input) {

    input = input.split(' ').map(v => ~~v)

    let s = Math.max(input[0], input[2])
    let g = Math.min(input[1], input[3])

    const ans = g - s > 0 ? g - s : 0


    console.log(ans)

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