import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abcd = br.readLine().split(" ");
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);
        
        int ans = Math.min(b, d) - Math.max(a, c);
        System.out.println(Math.max(ans, 0));
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abcd = br.readLine().split(" ");
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);
        
        int ans = Math.min(b, d) - Math.max(a, c);
        System.out.println(Math.max(ans, 0));
    }
} Main public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abcd = br.readLine().split(" ");
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);
        
        int ans = Math.min(b, d) - Math.max(a, c);
        System.out.println(Math.max(ans, 0));
    } main {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abcd = br.readLine().split(" ");
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);
        
        int ans = Math.min(b, d) - Math.max(a, c);
        System.out.println(Math.max(ans, 0));
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] abcd = br.readLine().split(" "); abcd br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int a = Integer.parseInt(abcd[0]); a Integer.parseInt(abcd[0]) Integer.parseInt Integer abcd[0] abcd 0 int b = Integer.parseInt(abcd[1]); b Integer.parseInt(abcd[1]) Integer.parseInt Integer abcd[1] abcd 1 int c = Integer.parseInt(abcd[2]); c Integer.parseInt(abcd[2]) Integer.parseInt Integer abcd[2] abcd 2 int d = Integer.parseInt(abcd[3]); d Integer.parseInt(abcd[3]) Integer.parseInt Integer abcd[3] abcd 3 int ans = Math.min(b, d) - Math.max(a, c); ans 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(Math.max(ans, 0)) System.out.println System.out System System.out Math.max(ans, 0) Math.max Math ans 0 String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abcd = br.readLine().split(" ");
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);
        
        int ans = Math.min(b, d) - Math.max(a, c);
        System.out.println(Math.max(ans, 0));
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abcd = br.readLine().split(" ");
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);
        
        int ans = Math.min(b, d) - Math.max(a, c);
        System.out.println(Math.max(ans, 0));
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abcd = br.readLine().split(" ");
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);
        
        int ans = Math.min(b, d) - Math.max(a, c);
        System.out.println(Math.max(ans, 0));
    }
}
