
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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 left = Math.max(a, c);
		int right = Math.min(b, d);
		
		if (right <= left) System.out.println(0);
		else System.out.println(right - left);
	}
} import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util import java.util.regex.Matcher; Matcher java.util.regex import java.util.regex.Pattern; Pattern java.util.regex 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 left = Math.max(a, c);
		int right = Math.min(b, d);
		
		if (right <= left) System.out.println(0);
		else System.out.println(right - left);
	}
} 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 left = Math.max(a, c);
		int right = Math.min(b, d);
		
		if (right <= left) System.out.println(0);
		else System.out.println(right - left);
	} main {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int left = Math.max(a, c);
		int right = Math.min(b, d);
		
		if (right <= left) System.out.println(0);
		else System.out.println(right - left);
	} 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 left = Math.max(a, c); left Math.max(a, c) Math.max Math a c int right = Math.min(b, d); right Math.min(b, d) Math.min Math b d if (right <= left) System.out.println(0);
		else System.out.println(right - left); right <= left right left System.out.println(0) System.out.println System.out System System.out 0 System.out.println(right - left) System.out.println System.out System System.out right - left right left String args[] args

import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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 left = Math.max(a, c);
		int right = Math.min(b, d);
		
		if (right <= left) System.out.println(0);
		else System.out.println(right - left);
	}
}