import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
		String[] number = line.split(" ");
		int a = Integer.parseInt(number[0]);
		int b = Integer.parseInt(number[1]);
		int c = Integer.parseInt(number[2]);
		int d = Integer.parseInt(number[3]);
		int r = 0;
		if(a <= c) {
			if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			}
		} else if(c < a) {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		}
	}
} 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 {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
		String[] number = line.split(" ");
		int a = Integer.parseInt(number[0]);
		int b = Integer.parseInt(number[1]);
		int c = Integer.parseInt(number[2]);
		int d = Integer.parseInt(number[3]);
		int r = 0;
		if(a <= c) {
			if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			}
		} else if(c < a) {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		}
	}
} Main public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
		String[] number = line.split(" ");
		int a = Integer.parseInt(number[0]);
		int b = Integer.parseInt(number[1]);
		int c = Integer.parseInt(number[2]);
		int d = Integer.parseInt(number[3]);
		int r = 0;
		if(a <= c) {
			if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			}
		} else if(c < a) {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		}
	} main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
		String[] number = line.split(" ");
		int a = Integer.parseInt(number[0]);
		int b = Integer.parseInt(number[1]);
		int c = Integer.parseInt(number[2]);
		int d = Integer.parseInt(number[3]);
		int r = 0;
		if(a <= c) {
			if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			}
		} else if(c < a) {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line = br.readLine(); line br.readLine() br.readLine br String[] number = line.split(" "); number line.split(" ") line.split line " " int a = Integer.parseInt(number[0]); a Integer.parseInt(number[0]) Integer.parseInt Integer number[0] number 0 int b = Integer.parseInt(number[1]); b Integer.parseInt(number[1]) Integer.parseInt Integer number[1] number 1 int c = Integer.parseInt(number[2]); c Integer.parseInt(number[2]) Integer.parseInt Integer number[2] number 2 int d = Integer.parseInt(number[3]); d Integer.parseInt(number[3]) Integer.parseInt Integer number[3] number 3 int r = 0; r 0 if(a <= c) {
			if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			}
		} else if(c < a) {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		} a <= c a c {
			if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			}
		} if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			} c < b c b {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    } b <= d b d {
				    r = b - c;
				    System.out.println(r);
			    } r = b - c r b - c b c System.out.println(r) System.out.println System.out System System.out r if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    } d < b d b {
			        r = d - c;
			        System.out.println(r);
			    } r = d - c r d - c d c System.out.println(r) System.out.println System.out System System.out r if(b <= c) {
				System.out.println(r);
			} b <= c b c {
				System.out.println(r);
			} System.out.println(r) System.out.println System.out System System.out r if(c < a) {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		} c < a c a {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		} if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			} a < d a d {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    } d <= b d b {
				    r = d - a;
				    System.out.println(r);
			    } r = d - a r d - a d a System.out.println(r) System.out.println System.out System System.out r if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    } b < d b d {
			        r = b - a;
			        System.out.println(r);
			    } r = b - a r b - a b a System.out.println(r) System.out.println System.out System System.out r if(d <= a) {
				System.out.println(r);
			} d <= a d a {
				System.out.println(r);
			} System.out.println(r) System.out.println System.out System System.out r String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
		String[] number = line.split(" ");
		int a = Integer.parseInt(number[0]);
		int b = Integer.parseInt(number[1]);
		int c = Integer.parseInt(number[2]);
		int d = Integer.parseInt(number[3]);
		int r = 0;
		if(a <= c) {
			if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			}
		} else if(c < a) {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		}
	}
} public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
		String[] number = line.split(" ");
		int a = Integer.parseInt(number[0]);
		int b = Integer.parseInt(number[1]);
		int c = Integer.parseInt(number[2]);
		int d = Integer.parseInt(number[3]);
		int r = 0;
		if(a <= c) {
			if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			}
		} else if(c < a) {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
		String[] number = line.split(" ");
		int a = Integer.parseInt(number[0]);
		int b = Integer.parseInt(number[1]);
		int c = Integer.parseInt(number[2]);
		int d = Integer.parseInt(number[3]);
		int r = 0;
		if(a <= c) {
			if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			}
		} else if(c < a) {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		}
	}
}