import java.util.Scanner;

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();
		if (b<=c || d <= a) {
			System.out.println(0);
			return;
		}
		if (a <= c) {
			if (d<=b) {
				System.out.println(d-c);
				return;				
			} else {
				System.out.println(b-c);
				return;
			}
		}
		if (a > c) {
			if (d<b) {
				System.out.println(d-a);
				return;				
			} else {
				System.out.println(b-a);
				return;
			}
		}
	}
} import java.util.Scanner; Scanner java.util 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();
		if (b<=c || d <= a) {
			System.out.println(0);
			return;
		}
		if (a <= c) {
			if (d<=b) {
				System.out.println(d-c);
				return;				
			} else {
				System.out.println(b-c);
				return;
			}
		}
		if (a > c) {
			if (d<b) {
				System.out.println(d-a);
				return;				
			} else {
				System.out.println(b-a);
				return;
			}
		}
	}
} 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();
		if (b<=c || d <= a) {
			System.out.println(0);
			return;
		}
		if (a <= c) {
			if (d<=b) {
				System.out.println(d-c);
				return;				
			} else {
				System.out.println(b-c);
				return;
			}
		}
		if (a > c) {
			if (d<b) {
				System.out.println(d-a);
				return;				
			} else {
				System.out.println(b-a);
				return;
			}
		}
	} main {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		if (b<=c || d <= a) {
			System.out.println(0);
			return;
		}
		if (a <= c) {
			if (d<=b) {
				System.out.println(d-c);
				return;				
			} else {
				System.out.println(b-c);
				return;
			}
		}
		if (a > c) {
			if (d<b) {
				System.out.println(d-a);
				return;				
			} else {
				System.out.println(b-a);
				return;
			}
		}
	} 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 if (b<=c || d <= a) {
			System.out.println(0);
			return;
		} b<=c || d <= a b<=c b c d <= a d a {
			System.out.println(0);
			return;
		} System.out.println(0) System.out.println System.out System System.out 0 return; if (a <= c) {
			if (d<=b) {
				System.out.println(d-c);
				return;				
			} else {
				System.out.println(b-c);
				return;
			}
		} a <= c a c {
			if (d<=b) {
				System.out.println(d-c);
				return;				
			} else {
				System.out.println(b-c);
				return;
			}
		} if (d<=b) {
				System.out.println(d-c);
				return;				
			} else {
				System.out.println(b-c);
				return;
			} d<=b d b {
				System.out.println(d-c);
				return;				
			} System.out.println(d-c) System.out.println System.out System System.out d-c d c return; {
				System.out.println(b-c);
				return;
			} System.out.println(b-c) System.out.println System.out System System.out b-c b c return; if (a > c) {
			if (d<b) {
				System.out.println(d-a);
				return;				
			} else {
				System.out.println(b-a);
				return;
			}
		} a > c a c {
			if (d<b) {
				System.out.println(d-a);
				return;				
			} else {
				System.out.println(b-a);
				return;
			}
		} if (d<b) {
				System.out.println(d-a);
				return;				
			} else {
				System.out.println(b-a);
				return;
			} d<b d b {
				System.out.println(d-a);
				return;				
			} System.out.println(d-a) System.out.println System.out System System.out d-a d a return; {
				System.out.println(b-a);
				return;
			} System.out.println(b-a) System.out.println System.out System System.out b-a b a return; 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();
		if (b<=c || d <= a) {
			System.out.println(0);
			return;
		}
		if (a <= c) {
			if (d<=b) {
				System.out.println(d-c);
				return;				
			} else {
				System.out.println(b-c);
				return;
			}
		}
		if (a > c) {
			if (d<b) {
				System.out.println(d-a);
				return;				
			} else {
				System.out.println(b-a);
				return;
			}
		}
	}
} 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();
		if (b<=c || d <= a) {
			System.out.println(0);
			return;
		}
		if (a <= c) {
			if (d<=b) {
				System.out.println(d-c);
				return;				
			} else {
				System.out.println(b-c);
				return;
			}
		}
		if (a > c) {
			if (d<b) {
				System.out.println(d-a);
				return;				
			} else {
				System.out.println(b-a);
				return;
			}
		}
	}
} Main
import java.util.Scanner;

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();
		if (b<=c || d <= a) {
			System.out.println(0);
			return;
		}
		if (a <= c) {
			if (d<=b) {
				System.out.println(d-c);
				return;				
			} else {
				System.out.println(b-c);
				return;
			}
		}
		if (a > c) {
			if (d<b) {
				System.out.println(d-a);
				return;				
			} else {
				System.out.println(b-a);
				return;
			}
		}
	}
}
