import java.util.*;
import java.lang.*;

public class Main {

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String[] inp = s.split(" ");
    int A = Integer.parseInt(inp[0]);
    int B = Integer.parseInt(inp[1]);
    int C = Integer.parseInt(inp[2]);
    int D = Integer.parseInt(inp[3]);
    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int out = end - start;
    if (out < 0) out = 0;
    System.out.println(out);
  }
}
 import java.util.*; util.* java import java.lang.*; lang.* java public class Main {

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String[] inp = s.split(" ");
    int A = Integer.parseInt(inp[0]);
    int B = Integer.parseInt(inp[1]);
    int C = Integer.parseInt(inp[2]);
    int D = Integer.parseInt(inp[3]);
    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int out = end - start;
    if (out < 0) out = 0;
    System.out.println(out);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String[] inp = s.split(" ");
    int A = Integer.parseInt(inp[0]);
    int B = Integer.parseInt(inp[1]);
    int C = Integer.parseInt(inp[2]);
    int D = Integer.parseInt(inp[3]);
    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int out = end - start;
    if (out < 0) out = 0;
    System.out.println(out);
  } main {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String[] inp = s.split(" ");
    int A = Integer.parseInt(inp[0]);
    int B = Integer.parseInt(inp[1]);
    int C = Integer.parseInt(inp[2]);
    int D = Integer.parseInt(inp[3]);
    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int out = end - start;
    if (out < 0) out = 0;
    System.out.println(out);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String s = sc.nextLine(); s sc.nextLine() sc.nextLine sc String[] inp = s.split(" "); inp s.split(" ") s.split s " " int A = Integer.parseInt(inp[0]); A Integer.parseInt(inp[0]) Integer.parseInt Integer inp[0] inp 0 int B = Integer.parseInt(inp[1]); B Integer.parseInt(inp[1]) Integer.parseInt Integer inp[1] inp 1 int C = Integer.parseInt(inp[2]); C Integer.parseInt(inp[2]) Integer.parseInt Integer inp[2] inp 2 int D = Integer.parseInt(inp[3]); D Integer.parseInt(inp[3]) Integer.parseInt Integer inp[3] inp 3 int start = Math.max(A, C); start Math.max(A, C) Math.max Math A C int end = Math.min(B, D); end Math.min(B, D) Math.min Math B D int out = end - start; out end - start end start if (out < 0) out = 0; out < 0 out 0 out = 0 out 0 System.out.println(out) System.out.println System.out System System.out out String[] args args public class Main {

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String[] inp = s.split(" ");
    int A = Integer.parseInt(inp[0]);
    int B = Integer.parseInt(inp[1]);
    int C = Integer.parseInt(inp[2]);
    int D = Integer.parseInt(inp[3]);
    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int out = end - start;
    if (out < 0) out = 0;
    System.out.println(out);
  }
} public class Main {

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String[] inp = s.split(" ");
    int A = Integer.parseInt(inp[0]);
    int B = Integer.parseInt(inp[1]);
    int C = Integer.parseInt(inp[2]);
    int D = Integer.parseInt(inp[3]);
    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int out = end - start;
    if (out < 0) out = 0;
    System.out.println(out);
  }
} Main
import java.util.*;
import java.lang.*;

public class Main {

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String[] inp = s.split(" ");
    int A = Integer.parseInt(inp[0]);
    int B = Integer.parseInt(inp[1]);
    int C = Integer.parseInt(inp[2]);
    int D = Integer.parseInt(inp[3]);
    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int out = end - start;
    if (out < 0) out = 0;
    System.out.println(out);
  }
}

