import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int x = 0,y = 0;
		if(a > c) {
			y = a;
			a = c;
			c = y;
			y = b;
			b = d;
			d = y;
		}
		if(b < c) {
			System.out.println(x);
		}else if(b < d ){
			x = (b - c);
			System.out.println(x);
		}else{
			x = (d - c);
			System.out.println(x);
		}
	}
}
 import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int x = 0,y = 0;
		if(a > c) {
			y = a;
			a = c;
			c = y;
			y = b;
			b = d;
			d = y;
		}
		if(b < c) {
			System.out.println(x);
		}else if(b < d ){
			x = (b - c);
			System.out.println(x);
		}else{
			x = (d - c);
			System.out.println(x);
		}
	}
} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int x = 0,y = 0;
		if(a > c) {
			y = a;
			a = c;
			c = y;
			y = b;
			b = d;
			d = y;
		}
		if(b < c) {
			System.out.println(x);
		}else if(b < d ){
			x = (b - c);
			System.out.println(x);
		}else{
			x = (d - c);
			System.out.println(x);
		}
	} main {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int x = 0,y = 0;
		if(a > c) {
			y = a;
			a = c;
			c = y;
			y = b;
			b = d;
			d = y;
		}
		if(b < c) {
			System.out.println(x);
		}else if(b < d ){
			x = (b - c);
			System.out.println(x);
		}else{
			x = (d - c);
			System.out.println(x);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int x = 0 x 0 y = 0; y 0 if(a > c) {
			y = a;
			a = c;
			c = y;
			y = b;
			b = d;
			d = y;
		} a > c a c {
			y = a;
			a = c;
			c = y;
			y = b;
			b = d;
			d = y;
		} y = a y a a = c a c c = y c y y = b y b b = d b d d = y d y if(b < c) {
			System.out.println(x);
		}else if(b < d ){
			x = (b - c);
			System.out.println(x);
		}else{
			x = (d - c);
			System.out.println(x);
		} b < c b c {
			System.out.println(x);
		} System.out.println(x) System.out.println System.out System System.out x if(b < d ){
			x = (b - c);
			System.out.println(x);
		}else{
			x = (d - c);
			System.out.println(x);
		} b < d b d {
			x = (b - c);
			System.out.println(x);
		} x = (b - c) x (b - c) b c System.out.println(x) System.out.println System.out System System.out x {
			x = (d - c);
			System.out.println(x);
		} x = (d - c) x (d - c) d c System.out.println(x) System.out.println System.out System System.out x String[] args args public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int x = 0,y = 0;
		if(a > c) {
			y = a;
			a = c;
			c = y;
			y = b;
			b = d;
			d = y;
		}
		if(b < c) {
			System.out.println(x);
		}else if(b < d ){
			x = (b - c);
			System.out.println(x);
		}else{
			x = (d - c);
			System.out.println(x);
		}
	}
} public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int x = 0,y = 0;
		if(a > c) {
			y = a;
			a = c;
			c = y;
			y = b;
			b = d;
			d = y;
		}
		if(b < c) {
			System.out.println(x);
		}else if(b < d ){
			x = (b - c);
			System.out.println(x);
		}else{
			x = (d - c);
			System.out.println(x);
		}
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int x = 0,y = 0;
		if(a > c) {
			y = a;
			a = c;
			c = y;
			y = b;
			b = d;
			d = y;
		}
		if(b < c) {
			System.out.println(x);
		}else if(b < d ){
			x = (b - c);
			System.out.println(x);
		}else{
			x = (d - c);
			System.out.println(x);
		}
	}
}

