import java.util.*;
/**
 * Created by 卢嘉昊 on 2017/8/12.
 */
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int D = scan.nextInt();
        int Alice = B-A;
        int Bob = D-C;
        int res = 0;
        if(A<C){
            if(B<C) res = 0;
            else if(B>D) res = Bob;
            else res = B-C;
        }else if(A == C){
            res = Alice < Bob ? Alice : Bob;
        }else{
            if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A;
        }
        System.out.println(res);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int D = scan.nextInt();
        int Alice = B-A;
        int Bob = D-C;
        int res = 0;
        if(A<C){
            if(B<C) res = 0;
            else if(B>D) res = Bob;
            else res = B-C;
        }else if(A == C){
            res = Alice < Bob ? Alice : Bob;
        }else{
            if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A;
        }
        System.out.println(res);
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int D = scan.nextInt();
        int Alice = B-A;
        int Bob = D-C;
        int res = 0;
        if(A<C){
            if(B<C) res = 0;
            else if(B>D) res = Bob;
            else res = B-C;
        }else if(A == C){
            res = Alice < Bob ? Alice : Bob;
        }else{
            if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A;
        }
        System.out.println(res);
    } main {
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int D = scan.nextInt();
        int Alice = B-A;
        int Bob = D-C;
        int res = 0;
        if(A<C){
            if(B<C) res = 0;
            else if(B>D) res = Bob;
            else res = B-C;
        }else if(A == C){
            res = Alice < Bob ? Alice : Bob;
        }else{
            if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A;
        }
        System.out.println(res);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int A = scan.nextInt(); A scan.nextInt() scan.nextInt scan int B = scan.nextInt(); B scan.nextInt() scan.nextInt scan int C = scan.nextInt(); C scan.nextInt() scan.nextInt scan int D = scan.nextInt(); D scan.nextInt() scan.nextInt scan int Alice = B-A; Alice B-A B A int Bob = D-C; Bob D-C D C int res = 0; res 0 if(A<C){
            if(B<C) res = 0;
            else if(B>D) res = Bob;
            else res = B-C;
        }else if(A == C){
            res = Alice < Bob ? Alice : Bob;
        }else{
            if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A;
        } A<C A C {
            if(B<C) res = 0;
            else if(B>D) res = Bob;
            else res = B-C;
        } if(B<C) res = 0;
            else if(B>D) res = Bob;
            else res = B-C; B<C B C res = 0 res 0 if(B>D) res = Bob;
            else res = B-C; B>D B D res = Bob res Bob res = B-C res B-C B C if(A == C){
            res = Alice < Bob ? Alice : Bob;
        }else{
            if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A;
        } A == C A C {
            res = Alice < Bob ? Alice : Bob;
        } res = Alice < Bob ? Alice : Bob res Alice < Bob ? Alice : Bob Alice < Bob Alice Bob Alice Bob {
            if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A;
        } if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A; A>=D A D res = 0 res 0 if(B>D) res = D-A;
            else res = B-A; B>D B D res = D-A res D-A D A res = B-A res B-A B A System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int D = scan.nextInt();
        int Alice = B-A;
        int Bob = D-C;
        int res = 0;
        if(A<C){
            if(B<C) res = 0;
            else if(B>D) res = Bob;
            else res = B-C;
        }else if(A == C){
            res = Alice < Bob ? Alice : Bob;
        }else{
            if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A;
        }
        System.out.println(res);
    }
} public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int D = scan.nextInt();
        int Alice = B-A;
        int Bob = D-C;
        int res = 0;
        if(A<C){
            if(B<C) res = 0;
            else if(B>D) res = Bob;
            else res = B-C;
        }else if(A == C){
            res = Alice < Bob ? Alice : Bob;
        }else{
            if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A;
        }
        System.out.println(res);
    }
} Main
import java.util.*;
/**
 * Created by 卢嘉昊 on 2017/8/12.
 */
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int D = scan.nextInt();
        int Alice = B-A;
        int Bob = D-C;
        int res = 0;
        if(A<C){
            if(B<C) res = 0;
            else if(B>D) res = Bob;
            else res = B-C;
        }else if(A == C){
            res = Alice < Bob ? Alice : Bob;
        }else{
            if(A>=D) res = 0;
            else if(B>D) res = D-A;
            else res = B-A;
        }
        System.out.println(res);
    }
}