function main(s) {
	s = s.split("\n")[0].split(" ").map(x => Number(x));
	console.log(Math.max(0, Math.min(s[1],s[3])-Math.max(s[0],s[2])));
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

