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

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int A = Integer.parseInt(s[0]);
        int B = Integer.parseInt(s[1]);
        int C = Integer.parseInt(s[2]);
        int D = Integer.parseInt(s[3]);
        if(A <= C) {
            if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            }
        }else {
            if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            }
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int A = Integer.parseInt(s[0]);
        int B = Integer.parseInt(s[1]);
        int C = Integer.parseInt(s[2]);
        int D = Integer.parseInt(s[3]);
        if(A <= C) {
            if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            }
        }else {
            if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            }
        }
    }
} Main public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int A = Integer.parseInt(s[0]);
        int B = Integer.parseInt(s[1]);
        int C = Integer.parseInt(s[2]);
        int D = Integer.parseInt(s[3]);
        if(A <= C) {
            if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            }
        }else {
            if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            }
        }
    } main {
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int A = Integer.parseInt(s[0]);
        int B = Integer.parseInt(s[1]);
        int C = Integer.parseInt(s[2]);
        int D = Integer.parseInt(s[3]);
        if(A <= C) {
            if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            }
        }else {
            if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            }
        }
    } BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in)); stdR new BufferedReader(new InputStreamReader(System.in)) String[] s = stdR.readLine().split(" "); s stdR.readLine().split(" ") stdR.readLine().split stdR.readLine() stdR.readLine stdR " " int A = Integer.parseInt(s[0]); A Integer.parseInt(s[0]) Integer.parseInt Integer s[0] s 0 int B = Integer.parseInt(s[1]); B Integer.parseInt(s[1]) Integer.parseInt Integer s[1] s 1 int C = Integer.parseInt(s[2]); C Integer.parseInt(s[2]) Integer.parseInt Integer s[2] s 2 int D = Integer.parseInt(s[3]); D Integer.parseInt(s[3]) Integer.parseInt Integer s[3] s 3 if(A <= C) {
            if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            }
        }else {
            if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            }
        } A <= C A C {
            if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            }
        } if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            } B <= C B C {
                System.out.println(0);
            } System.out.println(0) System.out.println System.out System System.out 0 if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            } 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 {
                System.out.println(D - C);
            } System.out.println(D - C) System.out.println System.out System System.out D - C D C {
            if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            }
        } if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            } D <= A D A {
                System.out.println(0);
            } System.out.println(0) System.out.println System.out System System.out 0 if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            } 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 {
                System.out.println(B - A);
            } System.out.println(B - A) System.out.println System.out System System.out B - A B A String args[] args public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int A = Integer.parseInt(s[0]);
        int B = Integer.parseInt(s[1]);
        int C = Integer.parseInt(s[2]);
        int D = Integer.parseInt(s[3]);
        if(A <= C) {
            if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            }
        }else {
            if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            }
        }
    }
} public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int A = Integer.parseInt(s[0]);
        int B = Integer.parseInt(s[1]);
        int C = Integer.parseInt(s[2]);
        int D = Integer.parseInt(s[3]);
        if(A <= C) {
            if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            }
        }else {
            if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            }
        }
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int A = Integer.parseInt(s[0]);
        int B = Integer.parseInt(s[1]);
        int C = Integer.parseInt(s[2]);
        int D = Integer.parseInt(s[3]);
        if(A <= C) {
            if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            }
        }else {
            if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            }
        }
    }
}
