import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] abcd = scanner.nextLine().split(" ", 4);
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);

        if (b <= c || d <= a) {
            System.out.println(0);
        } else {
            System.out.println(Math.min(b, d) - Math.max(c, a));
        }
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] abcd = scanner.nextLine().split(" ", 4);
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);

        if (b <= c || d <= a) {
            System.out.println(0);
        } else {
            System.out.println(Math.min(b, d) - Math.max(c, a));
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] abcd = scanner.nextLine().split(" ", 4);
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);

        if (b <= c || d <= a) {
            System.out.println(0);
        } else {
            System.out.println(Math.min(b, d) - Math.max(c, a));
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        String[] abcd = scanner.nextLine().split(" ", 4);
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);

        if (b <= c || d <= a) {
            System.out.println(0);
        } else {
            System.out.println(Math.min(b, d) - Math.max(c, a));
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] abcd = scanner.nextLine().split(" ", 4); abcd scanner.nextLine().split(" ", 4) scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " 4 int a = Integer.parseInt(abcd[0]); a Integer.parseInt(abcd[0]) Integer.parseInt Integer abcd[0] abcd 0 int b = Integer.parseInt(abcd[1]); b Integer.parseInt(abcd[1]) Integer.parseInt Integer abcd[1] abcd 1 int c = Integer.parseInt(abcd[2]); c Integer.parseInt(abcd[2]) Integer.parseInt Integer abcd[2] abcd 2 int d = Integer.parseInt(abcd[3]); d Integer.parseInt(abcd[3]) Integer.parseInt Integer abcd[3] abcd 3 if (b <= c || d <= a) {
            System.out.println(0);
        } else {
            System.out.println(Math.min(b, d) - Math.max(c, 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 {
            System.out.println(Math.min(b, d) - Math.max(c, a));
        } System.out.println(Math.min(b, d) - Math.max(c, a)) System.out.println System.out System System.out Math.min(b, d) - Math.max(c, a) Math.min(b, d) Math.min Math b d Math.max(c, a) Math.max Math c a String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] abcd = scanner.nextLine().split(" ", 4);
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);

        if (b <= c || d <= a) {
            System.out.println(0);
        } else {
            System.out.println(Math.min(b, d) - Math.max(c, a));
        }
    }
}
