import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		try(BufferedReader bf = new BufferedReader(new InputStreamReader(System.in))){
			 int A,B,C,D;
			 String[] s = bf.readLine().split(" ");
			 A = Integer.parseInt(s[0]);
			 B = Integer.parseInt(s[1]);
			 C = Integer.parseInt(s[2]);
			 D = Integer.parseInt(s[3]);
			 if(B<=C||D<=A) {
				 System.out.println(0);
			 }else if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 }
		}catch(IOException ioe) {
			ioe.getMessage();
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) {
		try(BufferedReader bf = new BufferedReader(new InputStreamReader(System.in))){
			 int A,B,C,D;
			 String[] s = bf.readLine().split(" ");
			 A = Integer.parseInt(s[0]);
			 B = Integer.parseInt(s[1]);
			 C = Integer.parseInt(s[2]);
			 D = Integer.parseInt(s[3]);
			 if(B<=C||D<=A) {
				 System.out.println(0);
			 }else if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 }
		}catch(IOException ioe) {
			ioe.getMessage();
		}
	}
} Main public static void main(String[] args) {
		try(BufferedReader bf = new BufferedReader(new InputStreamReader(System.in))){
			 int A,B,C,D;
			 String[] s = bf.readLine().split(" ");
			 A = Integer.parseInt(s[0]);
			 B = Integer.parseInt(s[1]);
			 C = Integer.parseInt(s[2]);
			 D = Integer.parseInt(s[3]);
			 if(B<=C||D<=A) {
				 System.out.println(0);
			 }else if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 }
		}catch(IOException ioe) {
			ioe.getMessage();
		}
	} main {
		try(BufferedReader bf = new BufferedReader(new InputStreamReader(System.in))){
			 int A,B,C,D;
			 String[] s = bf.readLine().split(" ");
			 A = Integer.parseInt(s[0]);
			 B = Integer.parseInt(s[1]);
			 C = Integer.parseInt(s[2]);
			 D = Integer.parseInt(s[3]);
			 if(B<=C||D<=A) {
				 System.out.println(0);
			 }else if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 }
		}catch(IOException ioe) {
			ioe.getMessage();
		}
	} try(BufferedReader bf = new BufferedReader(new InputStreamReader(System.in))){
			 int A,B,C,D;
			 String[] s = bf.readLine().split(" ");
			 A = Integer.parseInt(s[0]);
			 B = Integer.parseInt(s[1]);
			 C = Integer.parseInt(s[2]);
			 D = Integer.parseInt(s[3]);
			 if(B<=C||D<=A) {
				 System.out.println(0);
			 }else if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 }
		}catch(IOException ioe) {
			ioe.getMessage();
		} catch(IOException ioe) {
			ioe.getMessage();
		} IOException ioe {
			ioe.getMessage();
		} ioe.getMessage() ioe.getMessage ioe {
			 int A,B,C,D;
			 String[] s = bf.readLine().split(" ");
			 A = Integer.parseInt(s[0]);
			 B = Integer.parseInt(s[1]);
			 C = Integer.parseInt(s[2]);
			 D = Integer.parseInt(s[3]);
			 if(B<=C||D<=A) {
				 System.out.println(0);
			 }else if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 }
		} BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)) BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) int A A B B C C D; D String[] s = bf.readLine().split(" "); s bf.readLine().split(" ") bf.readLine().split bf.readLine() bf.readLine bf " " A = Integer.parseInt(s[0]) A Integer.parseInt(s[0]) Integer.parseInt Integer s[0] s 0 B = Integer.parseInt(s[1]) B Integer.parseInt(s[1]) Integer.parseInt Integer s[1] s 1 C = Integer.parseInt(s[2]) C Integer.parseInt(s[2]) Integer.parseInt Integer s[2] s 2 D = Integer.parseInt(s[3]) D Integer.parseInt(s[3]) Integer.parseInt Integer s[3] s 3 if(B<=C||D<=A) {
				 System.out.println(0);
			 }else if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 } B<=C||D<=A B<=C B C D<=A D A {
				 System.out.println(0);
			 } System.out.println(0) System.out.println System.out System System.out 0 if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 } A < C && C < B && B <= D A < C && C < B && B <= D A < C A C C < B C B B <= D B D {
				 System.out.println(B - C);
			 } System.out.println(B - C) System.out.println System.out System System.out B - C B C if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 } A < C &&  B > D A < C A C B > D B D {
				 System.out.println(D - C);
			 } System.out.println(D - C) System.out.println System.out System System.out D - C D C if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 } A >= C && B <= D A >= C A C B <= D B D {
				 System.out.println(B - A);
			 } System.out.println(B - A) System.out.println System.out System System.out B - A B A if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 } C < A && A < D && D <= B C < A && A < D && D <= B C < A C A A < D A D D <= B D B {
				 System.out.println(D - A);
			 } System.out.println(D - A) System.out.println System.out System System.out D - A D A String[] args args public class Main {

	public static void main(String[] args) {
		try(BufferedReader bf = new BufferedReader(new InputStreamReader(System.in))){
			 int A,B,C,D;
			 String[] s = bf.readLine().split(" ");
			 A = Integer.parseInt(s[0]);
			 B = Integer.parseInt(s[1]);
			 C = Integer.parseInt(s[2]);
			 D = Integer.parseInt(s[3]);
			 if(B<=C||D<=A) {
				 System.out.println(0);
			 }else if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 }
		}catch(IOException ioe) {
			ioe.getMessage();
		}
	}
} public class Main {

	public static void main(String[] args) {
		try(BufferedReader bf = new BufferedReader(new InputStreamReader(System.in))){
			 int A,B,C,D;
			 String[] s = bf.readLine().split(" ");
			 A = Integer.parseInt(s[0]);
			 B = Integer.parseInt(s[1]);
			 C = Integer.parseInt(s[2]);
			 D = Integer.parseInt(s[3]);
			 if(B<=C||D<=A) {
				 System.out.println(0);
			 }else if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 }
		}catch(IOException ioe) {
			ioe.getMessage();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		try(BufferedReader bf = new BufferedReader(new InputStreamReader(System.in))){
			 int A,B,C,D;
			 String[] s = bf.readLine().split(" ");
			 A = Integer.parseInt(s[0]);
			 B = Integer.parseInt(s[1]);
			 C = Integer.parseInt(s[2]);
			 D = Integer.parseInt(s[3]);
			 if(B<=C||D<=A) {
				 System.out.println(0);
			 }else if(A < C && C < B && B <= D) {
				 System.out.println(B - C);
			 }else if(A < C &&  B > D) {
				 System.out.println(D - C);
			 }else if(A >= C && B <= D) {
				 System.out.println(B - A);
			 }else if(C < A && A < D && D <= B) {
				 System.out.println(D - A);
			 }
		}catch(IOException ioe) {
			ioe.getMessage();
		}
	}
}