'use strict';
let execute = input => {
  const TIME = input.split(' ').map(el => +el);
  let executing = [];
  for (let i = Number(TIME[0]); i < TIME[1]; i++) {
    executing[i] = executing[i] === undefined ? 1 : executing[i] + 1;
  }
  for (let i = Number(TIME[2]); i < TIME[3]; i++) {
    executing[i] = executing[i] === undefined ? 1 : executing[i] + 1;
  }
  let ans = executing.reduce((prev, cur) => {
    return cur === 2 ? prev + 1 : prev;
  }, 0);
  return ans;
};

function Main(input) {
  console.log(execute(input));
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));