
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    //String s=gs();
	    int a=gi();
	    int b=gi();
	    int c=gi();
	    int d=gi();
	    
	    //System.out.print(String.valueOf(s.charAt(0))+ (s.length()-2)+s.charAt(s.length()-1));

	    if (b<=c || d<=a) {
        	System.out.print(0);
        }else if(a<=c && b<=d){
        	System.out.print(b-c);
        } else if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
} import java.util.Scanner; Scanner java.util public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    //String s=gs();
	    int a=gi();
	    int b=gi();
	    int c=gi();
	    int d=gi();
	    
	    //System.out.print(String.valueOf(s.charAt(0))+ (s.length()-2)+s.charAt(s.length()-1));

	    if (b<=c || d<=a) {
        	System.out.print(0);
        }else if(a<=c && b<=d){
        	System.out.print(b-c);
        } else if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
} Main static Scanner scanner; scanner public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    //String s=gs();
	    int a=gi();
	    int b=gi();
	    int c=gi();
	    int d=gi();
	    
	    //System.out.print(String.valueOf(s.charAt(0))+ (s.length()-2)+s.charAt(s.length()-1));

	    if (b<=c || d<=a) {
        	System.out.print(0);
        }else if(a<=c && b<=d){
        	System.out.print(b-c);
        } else if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        }


	} main {
	    scanner = new Scanner(System.in);

	    //String s=gs();
	    int a=gi();
	    int b=gi();
	    int c=gi();
	    int d=gi();
	    
	    //System.out.print(String.valueOf(s.charAt(0))+ (s.length()-2)+s.charAt(s.length()-1));

	    if (b<=c || d<=a) {
        	System.out.print(0);
        }else if(a<=c && b<=d){
        	System.out.print(b-c);
        } else if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        }


	} scanner = new Scanner(System.in) scanner new Scanner(System.in) int a=gi(); a gi() gi int b=gi(); b gi() gi int c=gi(); c gi() gi int d=gi(); d gi() gi if (b<=c || d<=a) {
        	System.out.print(0);
        }else if(a<=c && b<=d){
        	System.out.print(b-c);
        } else if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        } b<=c || d<=a b<=c b c d<=a d a {
        	System.out.print(0);
        } System.out.print(0) System.out.print System.out System System.out 0 if(a<=c && b<=d){
        	System.out.print(b-c);
        } else if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        } a<=c && b<=d a<=c a c b<=d b d {
        	System.out.print(b-c);
        } System.out.print(b-c) System.out.print System.out System System.out b-c b c if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        } c<=a && d<=b c<=a c a d<=b d b {
        	System.out.print(d-a);
        } System.out.print(d-a) System.out.print System.out System System.out d-a d a {
        	System.out.print(Math.min(b-a, d-c));
        } System.out.print(Math.min(b-a, d-c)) System.out.print System.out System System.out Math.min(b-a, d-c) Math.min Math b-a b a d-c d c String[] args args // 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	} gs {
		return scanner.next();
	} return scanner.next(); scanner.next() scanner.next scanner // intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	} gi {
		return Integer.parseInt(scanner.next());
	} return Integer.parseInt(scanner.next()); Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner // longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	} gl {
		return Long.parseLong(scanner.next());
	} return Long.parseLong(scanner.next()); Long.parseLong(scanner.next()) Long.parseLong Long scanner.next() scanner.next scanner // doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	} gd {
		return Double.parseDouble(scanner.next());
	} return Double.parseDouble(scanner.next()); Double.parseDouble(scanner.next()) Double.parseDouble Double scanner.next() scanner.next scanner public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    //String s=gs();
	    int a=gi();
	    int b=gi();
	    int c=gi();
	    int d=gi();
	    
	    //System.out.print(String.valueOf(s.charAt(0))+ (s.length()-2)+s.charAt(s.length()-1));

	    if (b<=c || d<=a) {
        	System.out.print(0);
        }else if(a<=c && b<=d){
        	System.out.print(b-c);
        } else if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
} public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    //String s=gs();
	    int a=gi();
	    int b=gi();
	    int c=gi();
	    int d=gi();
	    
	    //System.out.print(String.valueOf(s.charAt(0))+ (s.length()-2)+s.charAt(s.length()-1));

	    if (b<=c || d<=a) {
        	System.out.print(0);
        }else if(a<=c && b<=d){
        	System.out.print(b-c);
        } else if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
} Main

import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    //String s=gs();
	    int a=gi();
	    int b=gi();
	    int c=gi();
	    int d=gi();
	    
	    //System.out.print(String.valueOf(s.charAt(0))+ (s.length()-2)+s.charAt(s.length()-1));

	    if (b<=c || d<=a) {
        	System.out.print(0);
        }else if(a<=c && b<=d){
        	System.out.print(b-c);
        } else if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}