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();
        int ans = 0;
        if(a < c){
            if(b < c){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d < a){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            }
        }
        System.out.println(ans);
    }
} 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();
        int ans = 0;
        if(a < c){
            if(b < c){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d < a){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            }
        }
        System.out.println(ans);
    }
} 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 ans = 0;
        if(a < c){
            if(b < c){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d < a){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int ans = 0;
        if(a < c){
            if(b < c){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d < a){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            }
        }
        System.out.println(ans);
    } 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 ans = 0; ans 0 if(a < c){
            if(b < c){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d < a){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            }
        } a < c a c {
            if(b < c){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            }
        } if(b < c){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            } b < c b c {
                ans = 0;
            } ans = 0 ans 0 {
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            } if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                } b < d b d {
                    ans = b -  c;
                } ans = b -  c ans b -  c b c {
                    ans = d - c;
                } ans = d - c ans d - c d c {
            if(d < a){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            }
        } if(d < a){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            } d < a d a {
                ans = 0;
            } ans = 0 ans 0 {
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            } if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                } b < d b d {
                    ans = b -a;
                } ans = b -a ans b -a b a {
                    ans = d - a;
                } ans = d - a ans d - a d a System.out.println(ans) System.out.println System.out System System.out ans 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();
        int ans = 0;
        if(a < c){
            if(b < c){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d < a){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            }
        }
        System.out.println(ans);
    }
} 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();
        int ans = 0;
        if(a < c){
            if(b < c){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d < a){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            }
        }
        System.out.println(ans);
    }
} 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();
        int ans = 0;
        if(a < c){
            if(b < c){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -  c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d < a){
                ans = 0;
            }else{
                if(b < d){
                    ans = b -a;
                }else{
                    ans = d - a;
                }
            }
        }
        System.out.println(ans);
    }
}