import java.util.Scanner;
import java.io.*;
import java.util.*;

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

        int max = Math.max(a,c);
        int min = Math.min(b,d);
        int count = min -max;
        ans = Math.max(0, count);
        /* if(a<c && b<d && b<= c||c<a && b<d && b<=a ||a<c && d<b && d <= c ||c<a && d<b && d<=a){
            ans = 0;
        }
            else if(a<c && b<d && c<d){
                ans = b-c;
            }else if(c<a && b<d && a<d){
                ans = b-a;
            }else if(a<c && d<b && c<b){
                ans = d-c;
            }else if(c<a && d<b && a<b){
                ans = d-a;
            }
        */    
            System.out.println(ans);
        
        
    }

} import java.util.Scanner; Scanner java.util import java.io.*; io.* java import java.util.*; util.* java public class Main{
    public static void main(String args[]){
        Scanner scan_A = new Scanner(System.in);
        int a = scan_A.nextInt();
        int b = scan_A.nextInt();
        int c = scan_A.nextInt();
        int d = scan_A.nextInt();
        int ans;

        int max = Math.max(a,c);
        int min = Math.min(b,d);
        int count = min -max;
        ans = Math.max(0, count);
        /* if(a<c && b<d && b<= c||c<a && b<d && b<=a ||a<c && d<b && d <= c ||c<a && d<b && d<=a){
            ans = 0;
        }
            else if(a<c && b<d && c<d){
                ans = b-c;
            }else if(c<a && b<d && a<d){
                ans = b-a;
            }else if(a<c && d<b && c<b){
                ans = d-c;
            }else if(c<a && d<b && a<b){
                ans = d-a;
            }
        */    
            System.out.println(ans);
        
        
    }

} Main public static void main(String args[]){
        Scanner scan_A = new Scanner(System.in);
        int a = scan_A.nextInt();
        int b = scan_A.nextInt();
        int c = scan_A.nextInt();
        int d = scan_A.nextInt();
        int ans;

        int max = Math.max(a,c);
        int min = Math.min(b,d);
        int count = min -max;
        ans = Math.max(0, count);
        /* if(a<c && b<d && b<= c||c<a && b<d && b<=a ||a<c && d<b && d <= c ||c<a && d<b && d<=a){
            ans = 0;
        }
            else if(a<c && b<d && c<d){
                ans = b-c;
            }else if(c<a && b<d && a<d){
                ans = b-a;
            }else if(a<c && d<b && c<b){
                ans = d-c;
            }else if(c<a && d<b && a<b){
                ans = d-a;
            }
        */    
            System.out.println(ans);
        
        
    } main {
        Scanner scan_A = new Scanner(System.in);
        int a = scan_A.nextInt();
        int b = scan_A.nextInt();
        int c = scan_A.nextInt();
        int d = scan_A.nextInt();
        int ans;

        int max = Math.max(a,c);
        int min = Math.min(b,d);
        int count = min -max;
        ans = Math.max(0, count);
        /* if(a<c && b<d && b<= c||c<a && b<d && b<=a ||a<c && d<b && d <= c ||c<a && d<b && d<=a){
            ans = 0;
        }
            else if(a<c && b<d && c<d){
                ans = b-c;
            }else if(c<a && b<d && a<d){
                ans = b-a;
            }else if(a<c && d<b && c<b){
                ans = d-c;
            }else if(c<a && d<b && a<b){
                ans = d-a;
            }
        */    
            System.out.println(ans);
        
        
    } Scanner scan_A = new Scanner(System.in); scan_A new Scanner(System.in) int a = scan_A.nextInt(); a scan_A.nextInt() scan_A.nextInt scan_A int b = scan_A.nextInt(); b scan_A.nextInt() scan_A.nextInt scan_A int c = scan_A.nextInt(); c scan_A.nextInt() scan_A.nextInt scan_A int d = scan_A.nextInt(); d scan_A.nextInt() scan_A.nextInt scan_A int ans; ans int max = Math.max(a,c); max Math.max(a,c) Math.max Math a c int min = Math.min(b,d); min Math.min(b,d) Math.min Math b d int count = min -max; count min -max min max ans = Math.max(0, count) ans Math.max(0, count) Math.max Math 0 count System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main{
    public static void main(String args[]){
        Scanner scan_A = new Scanner(System.in);
        int a = scan_A.nextInt();
        int b = scan_A.nextInt();
        int c = scan_A.nextInt();
        int d = scan_A.nextInt();
        int ans;

        int max = Math.max(a,c);
        int min = Math.min(b,d);
        int count = min -max;
        ans = Math.max(0, count);
        /* if(a<c && b<d && b<= c||c<a && b<d && b<=a ||a<c && d<b && d <= c ||c<a && d<b && d<=a){
            ans = 0;
        }
            else if(a<c && b<d && c<d){
                ans = b-c;
            }else if(c<a && b<d && a<d){
                ans = b-a;
            }else if(a<c && d<b && c<b){
                ans = d-c;
            }else if(c<a && d<b && a<b){
                ans = d-a;
            }
        */    
            System.out.println(ans);
        
        
    }

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

        int max = Math.max(a,c);
        int min = Math.min(b,d);
        int count = min -max;
        ans = Math.max(0, count);
        /* if(a<c && b<d && b<= c||c<a && b<d && b<=a ||a<c && d<b && d <= c ||c<a && d<b && d<=a){
            ans = 0;
        }
            else if(a<c && b<d && c<d){
                ans = b-c;
            }else if(c<a && b<d && a<d){
                ans = b-a;
            }else if(a<c && d<b && c<b){
                ans = d-c;
            }else if(c<a && d<b && a<b){
                ans = d-a;
            }
        */    
            System.out.println(ans);
        
        
    }

} Main
import java.util.Scanner;
import java.io.*;
import java.util.*;

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

        int max = Math.max(a,c);
        int min = Math.min(b,d);
        int count = min -max;
        ans = Math.max(0, count);
        /* if(a<c && b<d && b<= c||c<a && b<d && b<=a ||a<c && d<b && d <= c ||c<a && d<b && d<=a){
            ans = 0;
        }
            else if(a<c && b<d && c<d){
                ans = b-c;
            }else if(c<a && b<d && a<d){
                ans = b-a;
            }else if(a<c && d<b && c<b){
                ans = d-c;
            }else if(c<a && d<b && a<b){
                ans = d-a;
            }
        */    
            System.out.println(ans);
        
        
    }

}