import java.util.*;
import java.util.stream.Collectors;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
      
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int result = 0;
        int lower;
        int upper;

        lower = Math.max(a, c);
        upper = Math.min(b, d);

        if (upper >= lower) {
            result = upper - lower;
        }

        System.out.println(result);
    }
} import java.util.*; util.* java import java.util.stream.Collectors; Collectors java.util.stream class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
      
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int result = 0;
        int lower;
        int upper;

        lower = Math.max(a, c);
        upper = Math.min(b, d);

        if (upper >= lower) {
            result = upper - lower;
        }

        System.out.println(result);
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
      
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int result = 0;
        int lower;
        int upper;

        lower = Math.max(a, c);
        upper = Math.min(b, d);

        if (upper >= lower) {
            result = upper - lower;
        }

        System.out.println(result);
    } main {
        Scanner sc = new Scanner(System.in);
      
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int result = 0;
        int lower;
        int upper;

        lower = Math.max(a, c);
        upper = Math.min(b, d);

        if (upper >= lower) {
            result = upper - lower;
        }

        System.out.println(result);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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 int result = 0; result 0 int lower; lower int upper; upper lower = Math.max(a, c) lower Math.max(a, c) Math.max Math a c upper = Math.min(b, d) upper Math.min(b, d) Math.min Math b d if (upper >= lower) {
            result = upper - lower;
        } upper >= lower upper lower {
            result = upper - lower;
        } result = upper - lower result upper - lower upper lower System.out.println(result) System.out.println System.out System System.out result String args[] args
import java.util.*;
import java.util.stream.Collectors;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
      
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int result = 0;
        int lower;
        int upper;

        lower = Math.max(a, c);
        upper = Math.min(b, d);

        if (upper >= lower) {
            result = upper - lower;
        }

        System.out.println(result);
    }
}