import java.util.Scanner;

public 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();
        sc.close();

        int sec;
        if (a <= c && c <= b && d <= b) {
            sec = d - c;
        } else if (a <= c && c <= b && d >= b) {
            sec = b - c;
        } else if (a >= c && a <= d && d <= b) {
            sec = d - a;
        } else if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        }
        System.out.println(sec);
    }
} import java.util.Scanner; Scanner java.util public 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();
        sc.close();

        int sec;
        if (a <= c && c <= b && d <= b) {
            sec = d - c;
        } else if (a <= c && c <= b && d >= b) {
            sec = b - c;
        } else if (a >= c && a <= d && d <= b) {
            sec = d - a;
        } else if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        }
        System.out.println(sec);
    }
} 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();
        sc.close();

        int sec;
        if (a <= c && c <= b && d <= b) {
            sec = d - c;
        } else if (a <= c && c <= b && d >= b) {
            sec = b - c;
        } else if (a >= c && a <= d && d <= b) {
            sec = d - a;
        } else if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        }
        System.out.println(sec);
    } main {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        sc.close();

        int sec;
        if (a <= c && c <= b && d <= b) {
            sec = d - c;
        } else if (a <= c && c <= b && d >= b) {
            sec = b - c;
        } else if (a >= c && a <= d && d <= b) {
            sec = d - a;
        } else if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        }
        System.out.println(sec);
    } 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 sc.close() sc.close sc int sec; sec if (a <= c && c <= b && d <= b) {
            sec = d - c;
        } else if (a <= c && c <= b && d >= b) {
            sec = b - c;
        } else if (a >= c && a <= d && d <= b) {
            sec = d - a;
        } else if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        } a <= c && c <= b && d <= b a <= c && c <= b && d <= b a <= c a c c <= b c b d <= b d b {
            sec = d - c;
        } sec = d - c sec d - c d c if (a <= c && c <= b && d >= b) {
            sec = b - c;
        } else if (a >= c && a <= d && d <= b) {
            sec = d - a;
        } else if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        } a <= c && c <= b && d >= b a <= c && c <= b && d >= b a <= c a c c <= b c b d >= b d b {
            sec = b - c;
        } sec = b - c sec b - c b c if (a >= c && a <= d && d <= b) {
            sec = d - a;
        } else if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        } a >= c && a <= d && d <= b a >= c && a <= d && d <= b a >= c a c a <= d a d d <= b d b {
            sec = d - a;
        } sec = d - a sec d - a d a if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        } a >= c && a <= d && d > b a >= c && a <= d && d > b a >= c a c a <= d a d d > b d b {
            sec = b - a;
        } sec = b - a sec b - a b a {
            sec = 0;
        } sec = 0 sec 0 System.out.println(sec) System.out.println System.out System System.out sec String[] args args public 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();
        sc.close();

        int sec;
        if (a <= c && c <= b && d <= b) {
            sec = d - c;
        } else if (a <= c && c <= b && d >= b) {
            sec = b - c;
        } else if (a >= c && a <= d && d <= b) {
            sec = d - a;
        } else if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        }
        System.out.println(sec);
    }
} public 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();
        sc.close();

        int sec;
        if (a <= c && c <= b && d <= b) {
            sec = d - c;
        } else if (a <= c && c <= b && d >= b) {
            sec = b - c;
        } else if (a >= c && a <= d && d <= b) {
            sec = d - a;
        } else if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        }
        System.out.println(sec);
    }
} Main
import java.util.Scanner;

public 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();
        sc.close();

        int sec;
        if (a <= c && c <= b && d <= b) {
            sec = d - c;
        } else if (a <= c && c <= b && d >= b) {
            sec = b - c;
        } else if (a >= c && a <= d && d <= b) {
            sec = d - a;
        } else if (a >= c && a <= d && d > b) {
            sec = b - a;
        } else {
            sec = 0;
        }
        System.out.println(sec);
    }
}
