import java.util.Scanner;


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();
		
		int time = 0;
		
		if(B<C)
		{
			time = 0;
		}
		else if(D<A)
		{
			time = 0;
		}
		else if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		}

		System.out.println(time);

	}

} import java.util.Scanner; Scanner 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();
		
		int time = 0;
		
		if(B<C)
		{
			time = 0;
		}
		else if(D<A)
		{
			time = 0;
		}
		else if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		}

		System.out.println(time);

	}

} 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();
		
		int time = 0;
		
		if(B<C)
		{
			time = 0;
		}
		else if(D<A)
		{
			time = 0;
		}
		else if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		}

		System.out.println(time);

	} main {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		
		int time = 0;
		
		if(B<C)
		{
			time = 0;
		}
		else if(D<A)
		{
			time = 0;
		}
		else if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		}

		System.out.println(time);

	} 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 int time = 0; time 0 if(B<C)
		{
			time = 0;
		}
		else if(D<A)
		{
			time = 0;
		}
		else if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		} B<C B C {
			time = 0;
		} time = 0 time 0 if(D<A)
		{
			time = 0;
		}
		else if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		} D<A D A {
			time = 0;
		} time = 0 time 0 if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		} A<C&&D<B A<C A C D<B D B {
			time = D-C;
		} time = D-C time D-C D C if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		} C<A&&B<D C<A C A B<D B D {
			time = B-A;
		} time = B-A time B-A B A if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		} A<C A C {
			time=B-C;
		} time=B-C time B-C B C if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		} C<A C A {
			time=D-A;
		} time=D-A time D-A D A if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		} C==A C A {
			time = B<D ?(B-A):(D-C); 
		} time = B<D ?(B-A):(D-C) time B<D ?(B-A):(D-C) B<D B D (B-A) B A (D-C) D C System.out.println(time) System.out.println System.out System System.out time 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();
		
		int time = 0;
		
		if(B<C)
		{
			time = 0;
		}
		else if(D<A)
		{
			time = 0;
		}
		else if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		}

		System.out.println(time);

	}

} 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();
		
		int time = 0;
		
		if(B<C)
		{
			time = 0;
		}
		else if(D<A)
		{
			time = 0;
		}
		else if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		}

		System.out.println(time);

	}

} Main
import java.util.Scanner;


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();
		
		int time = 0;
		
		if(B<C)
		{
			time = 0;
		}
		else if(D<A)
		{
			time = 0;
		}
		else if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		}

		System.out.println(time);

	}

}
