import java.util.*;
public 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();
    int s = Math.max(A,C);
    int e = Math.min(B,D);
    System.out.println(Math.max(0,e-s));
  }
  

  
} import java.util.*; util.* java public 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();
    int s = Math.max(A,C);
    int e = Math.min(B,D);
    System.out.println(Math.max(0,e-s));
  }
  

  
} 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();
    int s = Math.max(A,C);
    int e = Math.min(B,D);
    System.out.println(Math.max(0,e-s));
  } main {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    int s = Math.max(A,C);
    int e = Math.min(B,D);
    System.out.println(Math.max(0,e-s));
  } 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 int s = Math.max(A,C); s Math.max(A,C) Math.max Math A C int e = Math.min(B,D); e Math.min(B,D) Math.min Math B D System.out.println(Math.max(0,e-s)) System.out.println System.out System System.out Math.max(0,e-s) Math.max Math 0 e-s e s String[] args args public 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();
    int s = Math.max(A,C);
    int e = Math.min(B,D);
    System.out.println(Math.max(0,e-s));
  }
  

  
} public 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();
    int s = Math.max(A,C);
    int e = Math.min(B,D);
    System.out.println(Math.max(0,e-s));
  }
  

  
} Main
import java.util.*;
public 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();
    int s = Math.max(A,C);
    int e = Math.min(B,D);
    System.out.println(Math.max(0,e-s));
  }
  

  
}