'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));
  const A = s[0];
  const B = s[1];
  const C = s[2];
  const D = s[3];

  const lower = Math.max(A, C);
  const upper = Math.min(B, D);

  const answer = Math.max(0, upper - lower);
  console.log(answer);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
