import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

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 res = Math.max(0, Math.min(b,d)-Math.max(a,c));
        System.out.println(res);
        sc.close();
    }
}

class io {
    public static void br() {
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    }

    public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    }

}

class Algo {
    public static boolean isOdd(int n) {
        return n % 2 == 1;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }


}
 import java.util.*; util.* java import java.math.*; math.* java import java.io.*; io.* java import java.lang.*; lang.* java 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 res = Math.max(0, Math.min(b,d)-Math.max(a,c));
        System.out.println(res);
        sc.close();
    }
} 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 res = Math.max(0, Math.min(b,d)-Math.max(a,c));
        System.out.println(res);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int res = Math.max(0, Math.min(b,d)-Math.max(a,c));
        System.out.println(res);
        sc.close();
    } 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 res = Math.max(0, Math.min(b,d)-Math.max(a,c)); res Math.max(0, Math.min(b,d)-Math.max(a,c)) Math.max Math 0 Math.min(b,d)-Math.max(a,c) Math.min(b,d) Math.min Math b d Math.max(a,c) Math.max Math a c System.out.println(res) System.out.println System.out System System.out res sc.close() sc.close sc String[] args args class io {
    public static void br() {
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    }

    public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    }

} io public static void br() {
        System.out.println("");
    } br {
        System.out.println("");
    } System.out.println("") System.out.println System.out System System.out "" public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    } YesNo {
        System.out.println(f ? "Yes" : "No");
    } System.out.println(f ? "Yes" : "No") System.out.println System.out System System.out f ? "Yes" : "No" f "Yes" "No" boolean f f public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    } YESNO {
        System.out.println(f ? "YES" : "NO");
    } System.out.println(f ? "YES" : "NO") System.out.println System.out System System.out f ? "YES" : "NO" f "YES" "NO" boolean f f class Algo {
    public static boolean isOdd(int n) {
        return n % 2 == 1;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }


} Algo public static boolean isOdd(int n) {
        return n % 2 == 1;
    } isOdd {
        return n % 2 == 1;
    } return n % 2 == 1; n % 2 == 1 n % 2 n 2 1 int n n public static boolean isEven(int n) {
        return n % 2 == 0;
    } isEven {
        return n % 2 == 0;
    } return n % 2 == 0; n % 2 == 0 n % 2 n 2 0 int n n 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 res = Math.max(0, Math.min(b,d)-Math.max(a,c));
        System.out.println(res);
        sc.close();
    }
} 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 res = Math.max(0, Math.min(b,d)-Math.max(a,c));
        System.out.println(res);
        sc.close();
    }
} Main
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

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 res = Math.max(0, Math.min(b,d)-Math.max(a,c));
        System.out.println(res);
        sc.close();
    }
}

class io {
    public static void br() {
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    }

    public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    }

}

class Algo {
    public static boolean isOdd(int n) {
        return n % 2 == 1;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }


}

