import java.util.*;
import java.util.Arrays;
import java.util.Set;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        int D=sc.nextInt();
        if((C>=A)&&(C<=B)){
            System.out.println(Math.min(B,D)-C);
        }else if((A>=C)&&(D>=A)){
            System.out.println(Math.min(B,D)-A);
        }else{
            System.out.println(0);
        }

        }
        
        
    } import java.util.*; util.* java import java.util.Arrays; Arrays java.util import java.util.Set; Set java.util public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        int D=sc.nextInt();
        if((C>=A)&&(C<=B)){
            System.out.println(Math.min(B,D)-C);
        }else if((A>=C)&&(D>=A)){
            System.out.println(Math.min(B,D)-A);
        }else{
            System.out.println(0);
        }

        }
        
        
    } Main public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        int D=sc.nextInt();
        if((C>=A)&&(C<=B)){
            System.out.println(Math.min(B,D)-C);
        }else if((A>=C)&&(D>=A)){
            System.out.println(Math.min(B,D)-A);
        }else{
            System.out.println(0);
        }

        } main {
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        int D=sc.nextInt();
        if((C>=A)&&(C<=B)){
            System.out.println(Math.min(B,D)-C);
        }else if((A>=C)&&(D>=A)){
            System.out.println(Math.min(B,D)-A);
        }else{
            System.out.println(0);
        }

        } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int A=sc.nextInt(); A sc.nextInt() sc.nextInt sc int B=sc.nextInt(); B sc.nextInt() sc.nextInt sc int C=sc.nextInt(); C sc.nextInt() sc.nextInt sc int D=sc.nextInt(); D sc.nextInt() sc.nextInt sc if((C>=A)&&(C<=B)){
            System.out.println(Math.min(B,D)-C);
        }else if((A>=C)&&(D>=A)){
            System.out.println(Math.min(B,D)-A);
        }else{
            System.out.println(0);
        } (C>=A)&&(C<=B) (C>=A) C A (C<=B) C B {
            System.out.println(Math.min(B,D)-C);
        } System.out.println(Math.min(B,D)-C) System.out.println System.out System System.out Math.min(B,D)-C Math.min(B,D) Math.min Math B D C if((A>=C)&&(D>=A)){
            System.out.println(Math.min(B,D)-A);
        }else{
            System.out.println(0);
        } (A>=C)&&(D>=A) (A>=C) A C (D>=A) D A {
            System.out.println(Math.min(B,D)-A);
        } System.out.println(Math.min(B,D)-A) System.out.println System.out System System.out Math.min(B,D)-A Math.min(B,D) Math.min Math B D A {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 String[]args args public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        int D=sc.nextInt();
        if((C>=A)&&(C<=B)){
            System.out.println(Math.min(B,D)-C);
        }else if((A>=C)&&(D>=A)){
            System.out.println(Math.min(B,D)-A);
        }else{
            System.out.println(0);
        }

        }
        
        
    } public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        int D=sc.nextInt();
        if((C>=A)&&(C<=B)){
            System.out.println(Math.min(B,D)-C);
        }else if((A>=C)&&(D>=A)){
            System.out.println(Math.min(B,D)-A);
        }else{
            System.out.println(0);
        }

        }
        
        
    } Main
import java.util.*;
import java.util.Arrays;
import java.util.Set;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        int D=sc.nextInt();
        if((C>=A)&&(C<=B)){
            System.out.println(Math.min(B,D)-C);
        }else if((A>=C)&&(D>=A)){
            System.out.println(Math.min(B,D)-A);
        }else{
            System.out.println(0);
        }

        }
        
        
    }
