a,b,c,d = map(int,input().split())
t = False
if(a<=c<=b or a<=d<=b or c<=a<=d or c<=b<=d):
    t = True
else:
    t = False

if t:
    if(a<=c<=b and b<d):
        print(b-c)
    elif(a<=c<=b and b>=d):
        print(d-c)
    elif(a<=d<=b and a<=c):
        print(d-c)
    elif(a<=d<=b and a>c):
        print(d-a)
    elif(c<=a<=d and b<=d):
        print(b-a)
    elif(c<=a<=d and b>d):
        print(d-a)
    elif(c<=b<=d and a<c):
        print(b-c)
    elif(c<=b<=d and a>c):
        print(b-a)
else:
    print(0)