import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner (System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int d=stdIn.nextInt();
		int count=0;
		if(a>=c){
			if(b>=d){
				if(a<=d)
				count+=(d-a);
				else
					;
			}
			else
			count+=(b-a);
		}
		else if(b>=d){
			count+=(d-c);
		}
			else if(b>=c)
		count+=(b-c);
			else ;
		
		
		System.out.println(count);
		
			
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner (System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int d=stdIn.nextInt();
		int count=0;
		if(a>=c){
			if(b>=d){
				if(a<=d)
				count+=(d-a);
				else
					;
			}
			else
			count+=(b-a);
		}
		else if(b>=d){
			count+=(d-c);
		}
			else if(b>=c)
		count+=(b-c);
			else ;
		
		
		System.out.println(count);
		
			
	}

} Main public static void main(String[] args) {
		Scanner stdIn=new Scanner (System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int d=stdIn.nextInt();
		int count=0;
		if(a>=c){
			if(b>=d){
				if(a<=d)
				count+=(d-a);
				else
					;
			}
			else
			count+=(b-a);
		}
		else if(b>=d){
			count+=(d-c);
		}
			else if(b>=c)
		count+=(b-c);
			else ;
		
		
		System.out.println(count);
		
			
	} main {
		Scanner stdIn=new Scanner (System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int d=stdIn.nextInt();
		int count=0;
		if(a>=c){
			if(b>=d){
				if(a<=d)
				count+=(d-a);
				else
					;
			}
			else
			count+=(b-a);
		}
		else if(b>=d){
			count+=(d-c);
		}
			else if(b>=c)
		count+=(b-c);
			else ;
		
		
		System.out.println(count);
		
			
	} Scanner stdIn=new Scanner (System.in); stdIn new Scanner (System.in) int a=stdIn.nextInt(); a stdIn.nextInt() stdIn.nextInt stdIn int b=stdIn.nextInt(); b stdIn.nextInt() stdIn.nextInt stdIn int c=stdIn.nextInt(); c stdIn.nextInt() stdIn.nextInt stdIn int d=stdIn.nextInt(); d stdIn.nextInt() stdIn.nextInt stdIn int count=0; count 0 if(a>=c){
			if(b>=d){
				if(a<=d)
				count+=(d-a);
				else
					;
			}
			else
			count+=(b-a);
		}
		else if(b>=d){
			count+=(d-c);
		}
			else if(b>=c)
		count+=(b-c);
			else ; a>=c a c {
			if(b>=d){
				if(a<=d)
				count+=(d-a);
				else
					;
			}
			else
			count+=(b-a);
		} if(b>=d){
				if(a<=d)
				count+=(d-a);
				else
					;
			}
			else
			count+=(b-a); b>=d b d {
				if(a<=d)
				count+=(d-a);
				else
					;
			} if(a<=d)
				count+=(d-a);
				else
					; a<=d a d count+=(d-a) count (d-a) d a count+=(b-a) count (b-a) b a if(b>=d){
			count+=(d-c);
		}
			else if(b>=c)
		count+=(b-c);
			else ; b>=d b d {
			count+=(d-c);
		} count+=(d-c) count (d-c) d c if(b>=c)
		count+=(b-c);
			else ; b>=c b c count+=(b-c) count (b-c) b c System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner (System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int d=stdIn.nextInt();
		int count=0;
		if(a>=c){
			if(b>=d){
				if(a<=d)
				count+=(d-a);
				else
					;
			}
			else
			count+=(b-a);
		}
		else if(b>=d){
			count+=(d-c);
		}
			else if(b>=c)
		count+=(b-c);
			else ;
		
		
		System.out.println(count);
		
			
	}

} public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner (System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int d=stdIn.nextInt();
		int count=0;
		if(a>=c){
			if(b>=d){
				if(a<=d)
				count+=(d-a);
				else
					;
			}
			else
			count+=(b-a);
		}
		else if(b>=d){
			count+=(d-c);
		}
			else if(b>=c)
		count+=(b-c);
			else ;
		
		
		System.out.println(count);
		
			
	}

} Main
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner (System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int d=stdIn.nextInt();
		int count=0;
		if(a>=c){
			if(b>=d){
				if(a<=d)
				count+=(d-a);
				else
					;
			}
			else
			count+=(b-a);
		}
		else if(b>=d){
			count+=(d-c);
		}
			else if(b>=c)
		count+=(b-c);
			else ;
		
		
		System.out.println(count);
		
			
	}

}
