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