function Main(s) {
  var s = s.split("\n")[0].split(" ").map(e => e*1);
  var a = Math.max(s[0], s[2]), b = Math.min(s[1], s[3]);
  var c = a <= b;
  console.log(c ? b - a:0);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));