import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 Scanner in = new Scanner(System.in);
 int A = in.nextInt();
 int B = in.nextInt();
 int C = in.nextInt();
 int D = in.nextInt();

 int start = Math.max(A, C);
 int end = Math.min(B, D);

 if((A <= start)&&(start <= B)&&(C <= start)&&(start <= D)&&(A <= end)&&(end <= B)&&(C <= end)&&(end <= D)){
    System.out.println(end - start);
 }
 else{
	 System.out.println("0");
 }

 in.close();
}
} import java.util.Scanner; Scanner java.util public class Main {

public static void main(String[] args) {

 Scanner in = new Scanner(System.in);
 int A = in.nextInt();
 int B = in.nextInt();
 int C = in.nextInt();
 int D = in.nextInt();

 int start = Math.max(A, C);
 int end = Math.min(B, D);

 if((A <= start)&&(start <= B)&&(C <= start)&&(start <= D)&&(A <= end)&&(end <= B)&&(C <= end)&&(end <= D)){
    System.out.println(end - start);
 }
 else{
	 System.out.println("0");
 }

 in.close();
}
} Main public static void main(String[] args) {

 Scanner in = new Scanner(System.in);
 int A = in.nextInt();
 int B = in.nextInt();
 int C = in.nextInt();
 int D = in.nextInt();

 int start = Math.max(A, C);
 int end = Math.min(B, D);

 if((A <= start)&&(start <= B)&&(C <= start)&&(start <= D)&&(A <= end)&&(end <= B)&&(C <= end)&&(end <= D)){
    System.out.println(end - start);
 }
 else{
	 System.out.println("0");
 }

 in.close();
} main {

 Scanner in = new Scanner(System.in);
 int A = in.nextInt();
 int B = in.nextInt();
 int C = in.nextInt();
 int D = in.nextInt();

 int start = Math.max(A, C);
 int end = Math.min(B, D);

 if((A <= start)&&(start <= B)&&(C <= start)&&(start <= D)&&(A <= end)&&(end <= B)&&(C <= end)&&(end <= D)){
    System.out.println(end - start);
 }
 else{
	 System.out.println("0");
 }

 in.close();
} Scanner in = new Scanner(System.in); in new Scanner(System.in) int A = in.nextInt(); A in.nextInt() in.nextInt in int B = in.nextInt(); B in.nextInt() in.nextInt in int C = in.nextInt(); C in.nextInt() in.nextInt in int D = in.nextInt(); D in.nextInt() in.nextInt in int start = Math.max(A, C); start Math.max(A, C) Math.max Math A C int end = Math.min(B, D); end Math.min(B, D) Math.min Math B D if((A <= start)&&(start <= B)&&(C <= start)&&(start <= D)&&(A <= end)&&(end <= B)&&(C <= end)&&(end <= D)){
    System.out.println(end - start);
 }
 else{
	 System.out.println("0");
 } (A <= start)&&(start <= B)&&(C <= start)&&(start <= D)&&(A <= end)&&(end <= B)&&(C <= end)&&(end <= D) (C <= end) (end <= B) (A <= end) (start <= D) (C <= start) (A <= start)&&(start <= B)&&(C <= start)&&(start <= D)&&(A <= end)&&(end <= B)&&(C <= end)&&(end <= D) (A <= start) A start (start <= B) start B (C <= start) C start (start <= D) start D (A <= end) A end (end <= B) end B (C <= end) C end (end <= D) end D {
    System.out.println(end - start);
 } System.out.println(end - start) System.out.println System.out System System.out end - start end start {
	 System.out.println("0");
 } System.out.println("0") System.out.println System.out System System.out "0" in.close() in.close in String[] args args public class Main {

public static void main(String[] args) {

 Scanner in = new Scanner(System.in);
 int A = in.nextInt();
 int B = in.nextInt();
 int C = in.nextInt();
 int D = in.nextInt();

 int start = Math.max(A, C);
 int end = Math.min(B, D);

 if((A <= start)&&(start <= B)&&(C <= start)&&(start <= D)&&(A <= end)&&(end <= B)&&(C <= end)&&(end <= D)){
    System.out.println(end - start);
 }
 else{
	 System.out.println("0");
 }

 in.close();
}
} public class Main {

public static void main(String[] args) {

 Scanner in = new Scanner(System.in);
 int A = in.nextInt();
 int B = in.nextInt();
 int C = in.nextInt();
 int D = in.nextInt();

 int start = Math.max(A, C);
 int end = Math.min(B, D);

 if((A <= start)&&(start <= B)&&(C <= start)&&(start <= D)&&(A <= end)&&(end <= B)&&(C <= end)&&(end <= D)){
    System.out.println(end - start);
 }
 else{
	 System.out.println("0");
 }

 in.close();
}
} Main
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 Scanner in = new Scanner(System.in);
 int A = in.nextInt();
 int B = in.nextInt();
 int C = in.nextInt();
 int D = in.nextInt();

 int start = Math.max(A, C);
 int end = Math.min(B, D);

 if((A <= start)&&(start <= B)&&(C <= start)&&(start <= D)&&(A <= end)&&(end <= B)&&(C <= end)&&(end <= D)){
    System.out.println(end - start);
 }
 else{
	 System.out.println("0");
 }

 in.close();
}
}