import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  private static Scanner sc = new Scanner(System.in);

  private void run() {
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();

    int ans = Math.min(B, D) - Math.max(A, C);
    System.out.println(Math.max(ans, 0));
  }
} import java.util.Scanner; Scanner java.util class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  private static Scanner sc = new Scanner(System.in);

  private void run() {
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();

    int ans = Math.min(B, D) - Math.max(A, C);
    System.out.println(Math.max(ans, 0));
  }
} Main private static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
    new Main().run();
  } main {
    new Main().run();
  } new Main().run() new Main().run new Main() String[] args args private void run() {
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();

    int ans = Math.min(B, D) - Math.max(A, C);
    System.out.println(Math.max(ans, 0));
  } run {
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();

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

class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  private static Scanner sc = new Scanner(System.in);

  private void run() {
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();

    int ans = Math.min(B, D) - Math.max(A, C);
    System.out.println(Math.max(ans, 0));
  }
}
