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

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			int d = Integer.parseInt(s[3]);
			int total = 0;
			if(a < c) {
				if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				}
			}else {
				if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				}
			}

			if(total >= 0) {
				System.out.println(total);
			}else {
				total = 0;
				System.out.println(total);
			}

//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			int d = Integer.parseInt(s[3]);
			int total = 0;
			if(a < c) {
				if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				}
			}else {
				if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				}
			}

			if(total >= 0) {
				System.out.println(total);
			}else {
				total = 0;
				System.out.println(total);
			}

//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}
} Main public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			int d = Integer.parseInt(s[3]);
			int total = 0;
			if(a < c) {
				if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				}
			}else {
				if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				}
			}

			if(total >= 0) {
				System.out.println(total);
			}else {
				total = 0;
				System.out.println(total);
			}

//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			int d = Integer.parseInt(s[3]);
			int total = 0;
			if(a < c) {
				if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				}
			}else {
				if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				}
			}

			if(total >= 0) {
				System.out.println(total);
			}else {
				total = 0;
				System.out.println(total);
			}

//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			int d = Integer.parseInt(s[3]);
			int total = 0;
			if(a < c) {
				if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				}
			}else {
				if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				}
			}

			if(total >= 0) {
				System.out.println(total);
			}else {
				total = 0;
				System.out.println(total);
			}

//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		} catch (Exception e) {
			System.exit(0);
		} Exception e {
			System.exit(0);
		} System.exit(0) System.exit System 0 {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			int d = Integer.parseInt(s[3]);
			int total = 0;
			if(a < c) {
				if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				}
			}else {
				if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				}
			}

			if(total >= 0) {
				System.out.println(total);
			}else {
				total = 0;
				System.out.println(total);
			}

//			long max  = 1000000007;
		} String str = br.readLine(); str br.readLine() br.readLine br String[] s = str.split(" ",0); s str.split(" ",0) str.split str " " 0 int a = Integer.parseInt(s[0]); a Integer.parseInt(s[0]) Integer.parseInt Integer s[0] s 0 int b = Integer.parseInt(s[1]); b Integer.parseInt(s[1]) Integer.parseInt Integer s[1] s 1 int c = Integer.parseInt(s[2]); c Integer.parseInt(s[2]) Integer.parseInt Integer s[2] s 2 int d = Integer.parseInt(s[3]); d Integer.parseInt(s[3]) Integer.parseInt Integer s[3] s 3 int total = 0; total 0 if(a < c) {
				if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				}
			}else {
				if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				}
			} a < c a c {
				if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				}
			} if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				} b < d b d {
					total = b - c;
				} total = b - c total b - c b c {
					total = d - c;
				} total = d - c total d - c d c {
				if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				}
			} if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				} b < d b d {
					total = b - a;
				} total = b - a total b - a b a {
					total = d - a;
				} total = d - a total d - a d a if(total >= 0) {
				System.out.println(total);
			}else {
				total = 0;
				System.out.println(total);
			} total >= 0 total 0 {
				System.out.println(total);
			} System.out.println(total) System.out.println System.out System System.out total {
				total = 0;
				System.out.println(total);
			} total = 0 total 0 System.out.println(total) System.out.println System.out System System.out total String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			int d = Integer.parseInt(s[3]);
			int total = 0;
			if(a < c) {
				if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				}
			}else {
				if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				}
			}

			if(total >= 0) {
				System.out.println(total);
			}else {
				total = 0;
				System.out.println(total);
			}

//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}
}
