import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int left = Math.max(a, c);
        int right = Math.min(b, d);
        int ans = right - left;

        if(ans <0){
            System.out.println(0);
        } else {
            System.out.println(right - left);
        }
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.nio.charset.StandardCharsets; StandardCharsets java.nio.charset import java.util.*; util.* java public class Main {

    int[] inputArray;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int left = Math.max(a, c);
        int right = Math.min(b, d);
        int ans = right - left;

        if(ans <0){
            System.out.println(0);
        } else {
            System.out.println(right - left);
        }
    }

} Main int[] inputArray; inputArray public static void main(String[] args) throws IOException {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int left = Math.max(a, c);
        int right = Math.min(b, d);
        int ans = right - left;

        if(ans <0){
            System.out.println(0);
        } else {
            System.out.println(right - left);
        }
    } run {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int left = Math.max(a, c);
        int right = Math.min(b, d);
        int ans = right - left;

        if(ans <0){
            System.out.println(0);
        } else {
            System.out.println(right - left);
        }
    } 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 left = Math.max(a, c); left Math.max(a, c) Math.max Math a c int right = Math.min(b, d); right Math.min(b, d) Math.min Math b d int ans = right - left; ans right - left right left if(ans <0){
            System.out.println(0);
        } else {
            System.out.println(right - left);
        } ans <0 ans 0 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(right - left);
        } System.out.println(right - left) System.out.println System.out System System.out right - left right left public class Main {

    int[] inputArray;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int left = Math.max(a, c);
        int right = Math.min(b, d);
        int ans = right - left;

        if(ans <0){
            System.out.println(0);
        } else {
            System.out.println(right - left);
        }
    }

} public class Main {

    int[] inputArray;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int left = Math.max(a, c);
        int right = Math.min(b, d);
        int ans = right - left;

        if(ans <0){
            System.out.println(0);
        } else {
            System.out.println(right - left);
        }
    }

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int left = Math.max(a, c);
        int right = Math.min(b, d);
        int ans = right - left;

        if(ans <0){
            System.out.println(0);
        } else {
            System.out.println(right - left);
        }
    }

}