import java.util.*;

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        int lower = Math.max(a, c);
        int upper = Math.min(b, d);
        
        System.out.println(Math.max(0, upper - lower));

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        int lower = Math.max(a, c);
        int upper = Math.min(b, d);
        
        System.out.println(Math.max(0, upper - lower));

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        int lower = Math.max(a, c);
        int upper = Math.min(b, d);
        
        System.out.println(Math.max(0, upper - lower));

    } main {
        Scanner stdIn = new Scanner(System.in);

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        int lower = Math.max(a, c);
        int upper = Math.min(b, d);
        
        System.out.println(Math.max(0, upper - lower));

    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int a = stdIn.nextInt(); a stdIn.nextInt() stdIn.nextInt stdIn int b = stdIn.nextInt(); b stdIn.nextInt() stdIn.nextInt stdIn int c = stdIn.nextInt(); c stdIn.nextInt() stdIn.nextInt stdIn int d = stdIn.nextInt(); d stdIn.nextInt() stdIn.nextInt stdIn int lower = Math.max(a, c); lower Math.max(a, c) Math.max Math a c int upper = Math.min(b, d); upper Math.min(b, d) Math.min Math b d System.out.println(Math.max(0, upper - lower)) System.out.println System.out System System.out Math.max(0, upper - lower) Math.max Math 0 upper - lower upper lower String[] args args public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        int lower = Math.max(a, c);
        int upper = Math.min(b, d);
        
        System.out.println(Math.max(0, upper - lower));

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        int lower = Math.max(a, c);
        int upper = Math.min(b, d);
        
        System.out.println(Math.max(0, upper - lower));

    }
} Main
import java.util.*;

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        int lower = Math.max(a, c);
        int upper = Math.min(b, d);
        
        System.out.println(Math.max(0, upper - lower));

    }
}
