import java.util.*;
import java.math.*;

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();
      
      if(D <= A || B<=C){
          System.out.println(0);
          return;
      }else if(C <= A && D <= B){
          System.out.println(D-A);
          return;
      }else if(C<=A &&  B<=D){
          System.out.println(B-A);
          return;
      }else if(A<=C && D<=B){
          System.out.println(D-C);
          return;
      }else if(A<=C && B<=D){
          System.out.println(B-C);
          return;
      }      
      
      
   }
} import java.util.*; util.* java import java.math.*; math.* java 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();
      
      if(D <= A || B<=C){
          System.out.println(0);
          return;
      }else if(C <= A && D <= B){
          System.out.println(D-A);
          return;
      }else if(C<=A &&  B<=D){
          System.out.println(B-A);
          return;
      }else if(A<=C && D<=B){
          System.out.println(D-C);
          return;
      }else if(A<=C && B<=D){
          System.out.println(B-C);
          return;
      }      
      
      
   }
} 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();
      
      if(D <= A || B<=C){
          System.out.println(0);
          return;
      }else if(C <= A && D <= B){
          System.out.println(D-A);
          return;
      }else if(C<=A &&  B<=D){
          System.out.println(B-A);
          return;
      }else if(A<=C && D<=B){
          System.out.println(D-C);
          return;
      }else if(A<=C && B<=D){
          System.out.println(B-C);
          return;
      }      
      
      
   } main {

      Scanner sc = new Scanner(System.in);  
      
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      int D = sc.nextInt();
      
      if(D <= A || B<=C){
          System.out.println(0);
          return;
      }else if(C <= A && D <= B){
          System.out.println(D-A);
          return;
      }else if(C<=A &&  B<=D){
          System.out.println(B-A);
          return;
      }else if(A<=C && D<=B){
          System.out.println(D-C);
          return;
      }else if(A<=C && B<=D){
          System.out.println(B-C);
          return;
      }      
      
      
   } 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 if(D <= A || B<=C){
          System.out.println(0);
          return;
      }else if(C <= A && D <= B){
          System.out.println(D-A);
          return;
      }else if(C<=A &&  B<=D){
          System.out.println(B-A);
          return;
      }else if(A<=C && D<=B){
          System.out.println(D-C);
          return;
      }else if(A<=C && B<=D){
          System.out.println(B-C);
          return;
      } D <= A || B<=C D <= A D A B<=C B C {
          System.out.println(0);
          return;
      } System.out.println(0) System.out.println System.out System System.out 0 return; if(C <= A && D <= B){
          System.out.println(D-A);
          return;
      }else if(C<=A &&  B<=D){
          System.out.println(B-A);
          return;
      }else if(A<=C && D<=B){
          System.out.println(D-C);
          return;
      }else if(A<=C && B<=D){
          System.out.println(B-C);
          return;
      } C <= A && D <= B C <= A C A D <= B D B {
          System.out.println(D-A);
          return;
      } System.out.println(D-A) System.out.println System.out System System.out D-A D A return; if(C<=A &&  B<=D){
          System.out.println(B-A);
          return;
      }else if(A<=C && D<=B){
          System.out.println(D-C);
          return;
      }else if(A<=C && B<=D){
          System.out.println(B-C);
          return;
      } C<=A &&  B<=D C<=A C A B<=D B D {
          System.out.println(B-A);
          return;
      } System.out.println(B-A) System.out.println System.out System System.out B-A B A return; if(A<=C && D<=B){
          System.out.println(D-C);
          return;
      }else if(A<=C && B<=D){
          System.out.println(B-C);
          return;
      } A<=C && D<=B A<=C A C D<=B D B {
          System.out.println(D-C);
          return;
      } System.out.println(D-C) System.out.println System.out System System.out D-C D C return; if(A<=C && B<=D){
          System.out.println(B-C);
          return;
      } A<=C && B<=D A<=C A C B<=D B D {
          System.out.println(B-C);
          return;
      } System.out.println(B-C) System.out.println System.out System System.out B-C B C return; String[] args args
import java.util.*;
import java.math.*;

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();
      
      if(D <= A || B<=C){
          System.out.println(0);
          return;
      }else if(C <= A && D <= B){
          System.out.println(D-A);
          return;
      }else if(C<=A &&  B<=D){
          System.out.println(B-A);
          return;
      }else if(A<=C && D<=B){
          System.out.println(D-C);
          return;
      }else if(A<=C && B<=D){
          System.out.println(B-C);
          return;
      }      
      
      
   }
}