def resolve():
    a, b, c, d = map(int, input().split())
    if a > d or c > b:
        print(0)
        return
    print(min(b, d) - max(a, c))


resolve()

e7cb066eaf717c5e7300dc89ed0cdd48c4eeddc9
<mask token>

def resolve():
    a, b, c, d = map(int, input().split())
    if a > d or c > b:
        print(0)
        return
    print(min(b, d) - max(a, c))


<mask token>

def resolve():
    a, b, c, d = map(int, input().split())
    if a > d or c > b:
        print(0)
        return
    print(min(b, d) - max(a, c))


resolve()
