import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        int cnt;
        
        if( c >= b )cnt = 0;
        else{
          if( a >= c && b <= d )
            cnt = b-a;
          else if( d <= b && a >= c)
            cnt = d-a;
          else if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c;
        }
            
        if( cnt < 0 )cnt = 0;
        System.out.println(cnt);
	  }
} import java.util.*; util.* java public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        int cnt;
        
        if( c >= b )cnt = 0;
        else{
          if( a >= c && b <= d )
            cnt = b-a;
          else if( d <= b && a >= c)
            cnt = d-a;
          else if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c;
        }
            
        if( cnt < 0 )cnt = 0;
        System.out.println(cnt);
	  }
} Main public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        int cnt;
        
        if( c >= b )cnt = 0;
        else{
          if( a >= c && b <= d )
            cnt = b-a;
          else if( d <= b && a >= c)
            cnt = d-a;
          else if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c;
        }
            
        if( cnt < 0 )cnt = 0;
        System.out.println(cnt);
	  } main {
      	Scanner scan = new Scanner(System.in);
            
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        int cnt;
        
        if( c >= b )cnt = 0;
        else{
          if( a >= c && b <= d )
            cnt = b-a;
          else if( d <= b && a >= c)
            cnt = d-a;
          else if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c;
        }
            
        if( cnt < 0 )cnt = 0;
        System.out.println(cnt);
	  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int a = scan.nextInt(); a scan.nextInt() scan.nextInt scan int b = scan.nextInt(); b scan.nextInt() scan.nextInt scan int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan int d = scan.nextInt(); d scan.nextInt() scan.nextInt scan int cnt; cnt if( c >= b )cnt = 0;
        else{
          if( a >= c && b <= d )
            cnt = b-a;
          else if( d <= b && a >= c)
            cnt = d-a;
          else if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c;
        } c >= b c b cnt = 0 cnt 0 {
          if( a >= c && b <= d )
            cnt = b-a;
          else if( d <= b && a >= c)
            cnt = d-a;
          else if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c;
        } if( a >= c && b <= d )
            cnt = b-a;
          else if( d <= b && a >= c)
            cnt = d-a;
          else if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c; a >= c && b <= d a >= c a c b <= d b d cnt = b-a cnt b-a b a if( d <= b && a >= c)
            cnt = d-a;
          else if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c; d <= b && a >= c d <= b d b a >= c a c cnt = d-a cnt d-a d a if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c; d <= b && a < c d <= b d b a < c a c cnt = d-c cnt d-c d c cnt = b-c cnt b-c b c if( cnt < 0 )cnt = 0; cnt < 0 cnt 0 cnt = 0 cnt 0 System.out.println(cnt) System.out.println System.out System System.out cnt String args[] args public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        int cnt;
        
        if( c >= b )cnt = 0;
        else{
          if( a >= c && b <= d )
            cnt = b-a;
          else if( d <= b && a >= c)
            cnt = d-a;
          else if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c;
        }
            
        if( cnt < 0 )cnt = 0;
        System.out.println(cnt);
	  }
} public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        int cnt;
        
        if( c >= b )cnt = 0;
        else{
          if( a >= c && b <= d )
            cnt = b-a;
          else if( d <= b && a >= c)
            cnt = d-a;
          else if( d <= b && a < c)
            cnt = d-c;
          else
            cnt = b-c;
        }
            
        if( cnt < 0 )cnt = 0;
        System.out.println(cnt);
	  }
} Main
import java.util.*;

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