import java.util.*;

public class Main {
  public static void main(final String[] args) {
    final Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    sc.close();

    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int ans = end - start;
    if (ans < 0) {
      ans = 0;
    }
    System.out.println(ans);
  }
} import java.util.*; util.* java public class Main {
  public static void main(final String[] args) {
    final Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    sc.close();

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

    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int ans = end - start;
    if (ans < 0) {
      ans = 0;
    }
    System.out.println(ans);
  } main {
    final Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    sc.close();

    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int ans = end - start;
    if (ans < 0) {
      ans = 0;
    }
    System.out.println(ans);
  } final 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 sc.close() sc.close sc 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 ans = end - start; ans end - start end start if (ans < 0) {
      ans = 0;
    } ans < 0 ans 0 {
      ans = 0;
    } ans = 0 ans 0 System.out.println(ans) System.out.println System.out System System.out ans final String[] args args public class Main {
  public static void main(final String[] args) {
    final Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    sc.close();

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

    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int ans = end - start;
    if (ans < 0) {
      ans = 0;
    }
    System.out.println(ans);
  }
} Main
import java.util.*;

public class Main {
  public static void main(final String[] args) {
    final Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    sc.close();

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