extension Optional {
    func puts(){
        print(self!)
    }
}

readLine().map { line -> Int in 
    let l = line.split(separator: " ").compactMap { Int($0) }
    let (a, b, c, d) = (l[0], l[1], l[2], l[3])
    let left = max(a, c)
    let right = min(b, d)

    return max(0, right - left)
}.puts()