import java.util.*;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int kekka = 0;

        if(a < c){
        	if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	}
        }

        if(c < a){
        	if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	}
        }

        else if(a==c){
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        }

        System.out.println(kekka);
    }
} import java.util.*; util.* java import java.util.Arrays; Arrays java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int kekka = 0;

        if(a < c){
        	if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	}
        }

        if(c < a){
        	if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	}
        }

        else if(a==c){
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        }

        System.out.println(kekka);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int kekka = 0;

        if(a < c){
        	if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	}
        }

        if(c < a){
        	if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	}
        }

        else if(a==c){
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        }

        System.out.println(kekka);
    } main {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int kekka = 0;

        if(a < c){
        	if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	}
        }

        if(c < a){
        	if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	}
        }

        else if(a==c){
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        }

        System.out.println(kekka);
    } 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 kekka = 0; kekka 0 if(a < c){
        	if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	}
        } a < c a c {
        	if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	}
        } if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	} c < b c b {
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	} if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		} b < d b d {
        			kekka = b - c;
        		} kekka = b - c kekka b - c b c {
        			kekka = d - c;
        		} kekka = d - c kekka d - c d c if(c < a){
        	if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	}
        }

        else if(a==c){
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        } c < a c a {
        	if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	}
        } if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	} a < d a d {
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	} if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		} d < b d b {
        			kekka = d - a;
        		} kekka = d - a kekka d - a d a {
        			kekka = b - a;
        		} kekka = b - a kekka b - a b a if(a==c){
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        } a==c a c {
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        } if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	} b < d b d {
        		kekka = b - a;
        	} kekka = b - a kekka b - a b a {
        		kekka = d - a;
        	} kekka = d - a kekka d - a d a System.out.println(kekka) System.out.println System.out System System.out kekka String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int kekka = 0;

        if(a < c){
        	if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	}
        }

        if(c < a){
        	if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	}
        }

        else if(a==c){
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        }

        System.out.println(kekka);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int kekka = 0;

        if(a < c){
        	if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	}
        }

        if(c < a){
        	if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	}
        }

        else if(a==c){
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        }

        System.out.println(kekka);
    }
} Main
import java.util.*;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int kekka = 0;

        if(a < c){
        	if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	}
        }

        if(c < a){
        	if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	}
        }

        else if(a==c){
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        }

        System.out.println(kekka);
    }
}