const input = require('fs').readFileSync('/dev/stdin', 'utf8');
// input: 'A　B'
const inputList = input.split(' '); // 空白文字に注意
const inputNumberList = inputList.map(Number);
const a = inputNumberList[0];
const b = inputNumberList[1];
const c = inputNumberList[2];
const d = inputNumberList[3];

if (a <= c &&  d <= b) {
  console.log(d - c);
} else if (a <= c && c <= b && b <= d) {
  console.log(b - c);
} else if (c <= a && a <= d && d <= b) {
  console.log(d-a);
} else if (c <= a && b <= d) {
  console.log(b - a);
} else {
  console.log(0);
}