import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    static void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if (d <= a || b <= c) {
            System.out.println(0);
            return;
        }

        if (c <= a) {
            if (d <= b) {
                System.out.println(d - a);
            } else {
                System.out.println(b - a);
            }
        } else if (c < b) {
            if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    static void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if (d <= a || b <= c) {
            System.out.println(0);
            return;
        }

        if (c <= a) {
            if (d <= b) {
                System.out.println(d - a);
            } else {
                System.out.println(b - a);
            }
        } else if (c < b) {
            if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            }
        }
    }
} Main public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    } main {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    } try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        } {
            solve(sc);
        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) solve(sc) solve sc String[] args args static void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if (d <= a || b <= c) {
            System.out.println(0);
            return;
        }

        if (c <= a) {
            if (d <= b) {
                System.out.println(d - a);
            } else {
                System.out.println(b - a);
            }
        } else if (c < b) {
            if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            }
        }
    } solve {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if (d <= a || b <= c) {
            System.out.println(0);
            return;
        }

        if (c <= a) {
            if (d <= b) {
                System.out.println(d - a);
            } else {
                System.out.println(b - a);
            }
        } else if (c < b) {
            if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            }
        }
    } int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc if (d <= a || b <= c) {
            System.out.println(0);
            return;
        } d <= a || b <= c d <= a d a b <= c b c {
            System.out.println(0);
            return;
        } System.out.println(0) System.out.println System.out System System.out 0 return; if (c <= a) {
            if (d <= b) {
                System.out.println(d - a);
            } else {
                System.out.println(b - a);
            }
        } else if (c < b) {
            if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            }
        } c <= a c a {
            if (d <= b) {
                System.out.println(d - a);
            } else {
                System.out.println(b - a);
            }
        } 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 if (c < b) {
            if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            }
        } c < b c b {
            if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            }
        } if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            } d <= b d b {
                System.out.println(d - c);
            } System.out.println(d - c) System.out.println System.out System System.out d - c d c {
                System.out.println(b - c);
            } System.out.println(b - c) System.out.println System.out System System.out b - c b c Scanner sc sc public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    static void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if (d <= a || b <= c) {
            System.out.println(0);
            return;
        }

        if (c <= a) {
            if (d <= b) {
                System.out.println(d - a);
            } else {
                System.out.println(b - a);
            }
        } else if (c < b) {
            if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    static void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if (d <= a || b <= c) {
            System.out.println(0);
            return;
        }

        if (c <= a) {
            if (d <= b) {
                System.out.println(d - a);
            } else {
                System.out.println(b - a);
            }
        } else if (c < b) {
            if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    static void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if (d <= a || b <= c) {
            System.out.println(0);
            return;
        }

        if (c <= a) {
            if (d <= b) {
                System.out.println(d - a);
            } else {
                System.out.println(b - a);
            }
        } else if (c < b) {
            if (d <= b) {
                System.out.println(d - c);
            } else {
                System.out.println(b - c);
            }
        }
    }
}