import java.util.*;

class Main{
   public static void main(String[] argv){
      int A, B, C, D;
      
      Scanner stdIn = new Scanner(System.in);
      A = stdIn.nextInt();
      B = stdIn.nextInt();
      C = stdIn.nextInt();
      D = stdIn.nextInt();
      
      if(B<=C){
         System.out.print(0);
      }else if(A<C&&C<B&&B<D){
         System.out.print(B-C);
      }else if(A<=C&&D<=B){
         System.out.print(D-C);
      }else if(D<=A){
         System.out.print(0);
      }else if(C<A&&A<D&&D<B){
         System.out.print(D-A);
      }else if(C<=A&&B<=D){
         System.out.print(B-A);
      }
   }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz