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;

        for (int i = a; i <= b; i++) {
            for (int j = c; j <= d; j++) {
                if (i == j) {
                    result++;
                    break;
                }
            }
        }

        if (result > 0) {
            result--;
        }

        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;

        for (int i = a; i <= b; i++) {
            for (int j = c; j <= d; j++) {
                if (i == j) {
                    result++;
                    break;
                }
            }
        }

        if (result > 0) {
            result--;
        }

        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;

        for (int i = a; i <= b; i++) {
            for (int j = c; j <= d; j++) {
                if (i == j) {
                    result++;
                    break;
                }
            }
        }

        if (result > 0) {
            result--;
        }

        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;

        for (int i = a; i <= b; i++) {
            for (int j = c; j <= d; j++) {
                if (i == j) {
                    result++;
                    break;
                }
            }
        }

        if (result > 0) {
            result--;
        }

        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 for (int i = a; i <= b; i++) {
            for (int j = c; j <= d; j++) {
                if (i == j) {
                    result++;
                    break;
                }
            }
        } int i = a; int i = a; i a i <= b i b i++ i++ i {
            for (int j = c; j <= d; j++) {
                if (i == j) {
                    result++;
                    break;
                }
            }
        } {
            for (int j = c; j <= d; j++) {
                if (i == j) {
                    result++;
                    break;
                }
            }
        } for (int j = c; j <= d; j++) {
                if (i == j) {
                    result++;
                    break;
                }
            } int j = c; int j = c; j c j <= d j d j++ j++ j {
                if (i == j) {
                    result++;
                    break;
                }
            } {
                if (i == j) {
                    result++;
                    break;
                }
            } if (i == j) {
                    result++;
                    break;
                } i == j i j {
                    result++;
                    break;
                } result++ result break; if (result > 0) {
            result--;
        } result > 0 result 0 {
            result--;
        } result-- result 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;

        for (int i = a; i <= b; i++) {
            for (int j = c; j <= d; j++) {
                if (i == j) {
                    result++;
                    break;
                }
            }
        }

        if (result > 0) {
            result--;
        }

        System.out.println(result);
    }
}