import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int time = 0;

        if (A <= C) {
            if (B <= C) {
                time = 0;
            } else if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            }
        } else {
            if (D <= A) {
                time = 0;
            } else if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(time);

        sc.close();
        out.flush();
    }
} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int time = 0;

        if (A <= C) {
            if (B <= C) {
                time = 0;
            } else if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            }
        } else {
            if (D <= A) {
                time = 0;
            } else if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(time);

        sc.close();
        out.flush();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int time = 0;

        if (A <= C) {
            if (B <= C) {
                time = 0;
            } else if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            }
        } else {
            if (D <= A) {
                time = 0;
            } else if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(time);

        sc.close();
        out.flush();
    } main {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int time = 0;

        if (A <= C) {
            if (B <= C) {
                time = 0;
            } else if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            }
        } else {
            if (D <= A) {
                time = 0;
            } else if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(time);

        sc.close();
        out.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int A = Integer.parseInt(sc.next()); A Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int B = Integer.parseInt(sc.next()); B Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int C = Integer.parseInt(sc.next()); C Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int D = Integer.parseInt(sc.next()); D Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int time = 0; time 0 if (A <= C) {
            if (B <= C) {
                time = 0;
            } else if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            }
        } else {
            if (D <= A) {
                time = 0;
            } else if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            }
        } A <= C A C {
            if (B <= C) {
                time = 0;
            } else if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            }
        } if (B <= C) {
                time = 0;
            } else if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            } B <= C B C {
                time = 0;
            } time = 0 time 0 if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            } C < B && B <= D C < B C B B <= D B D {
                time = B - C;
            } time = B - C time B - C B C if (D < B) {
                time = D - C;
            } D < B D B {
                time = D - C;
            } time = D - C time D - C D C {
            if (D <= A) {
                time = 0;
            } else if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            }
        } if (D <= A) {
                time = 0;
            } else if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            } D <= A D A {
                time = 0;
            } time = 0 time 0 if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            } A < D && D <= B A < D A D D <= B D B {
                time = D - A;
            } time = D - A time D - A D A if (B < D) {
                time = B - A;
            } B < D B D {
                time = B - A;
            } time = B - A time B - A B A PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) out.println(time) out.println out time sc.close() sc.close sc out.flush() out.flush out String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int time = 0;

        if (A <= C) {
            if (B <= C) {
                time = 0;
            } else if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            }
        } else {
            if (D <= A) {
                time = 0;
            } else if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(time);

        sc.close();
        out.flush();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int time = 0;

        if (A <= C) {
            if (B <= C) {
                time = 0;
            } else if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            }
        } else {
            if (D <= A) {
                time = 0;
            } else if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(time);

        sc.close();
        out.flush();
    }
} Main
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int time = 0;

        if (A <= C) {
            if (B <= C) {
                time = 0;
            } else if (C < B && B <= D) {
                time = B - C;
            } else if (D < B) {
                time = D - C;
            }
        } else {
            if (D <= A) {
                time = 0;
            } else if (A < D && D <= B) {
                time = D - A;
            } else if (B < D) {
                time = B - A;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(time);

        sc.close();
        out.flush();
    }
}