
import java.util.Scanner;

public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final int A;
    private final int B;
    private final int C;
    private final int D;

    public Main() {
	A = Integer.parseInt(scan.next());
	B = Integer.parseInt(scan.next());
	C = Integer.parseInt(scan.next());
	D = Integer.parseInt(scan.next());
	scan.close();
    }

    public final void answer() {
	int start = Integer.max(A, C);
	int end = Integer.min(B, D);
	int time = end - start;
	if(time < 0) time = 0;

	System.out.println(time);
    }
} import java.util.Scanner; Scanner java.util public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final int A;
    private final int B;
    private final int C;
    private final int D;

    public Main() {
	A = Integer.parseInt(scan.next());
	B = Integer.parseInt(scan.next());
	C = Integer.parseInt(scan.next());
	D = Integer.parseInt(scan.next());
	scan.close();
    }

    public final void answer() {
	int start = Integer.max(A, C);
	int end = Integer.min(B, D);
	int time = end - start;
	if(time < 0) time = 0;

	System.out.println(time);
    }
} Main private Scanner scan = new Scanner(System.in); scan new Scanner(System.in) private final int A; A private final int B; B private final int C; C private final int D; D public static void main(String[] args) {
	Main m = new Main();
	m.answer();
    } main {
	Main m = new Main();
	m.answer();
    } Main m = new Main(); m new Main() m.answer() m.answer m String[] args args public Main() {
	A = Integer.parseInt(scan.next());
	B = Integer.parseInt(scan.next());
	C = Integer.parseInt(scan.next());
	D = Integer.parseInt(scan.next());
	scan.close();
    } Main {
	A = Integer.parseInt(scan.next());
	B = Integer.parseInt(scan.next());
	C = Integer.parseInt(scan.next());
	D = Integer.parseInt(scan.next());
	scan.close();
    } A = Integer.parseInt(scan.next()) A Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan B = Integer.parseInt(scan.next()) B Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan C = Integer.parseInt(scan.next()) C Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan D = Integer.parseInt(scan.next()) D Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan scan.close() scan.close scan public final void answer() {
	int start = Integer.max(A, C);
	int end = Integer.min(B, D);
	int time = end - start;
	if(time < 0) time = 0;

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

	System.out.println(time);
    } int start = Integer.max(A, C); start Integer.max(A, C) Integer.max Integer A C int end = Integer.min(B, D); end Integer.min(B, D) Integer.min Integer B D int time = end - start; time end - start end start if(time < 0) time = 0; time < 0 time 0 time = 0 time 0 System.out.println(time) System.out.println System.out System System.out time public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final int A;
    private final int B;
    private final int C;
    private final int D;

    public Main() {
	A = Integer.parseInt(scan.next());
	B = Integer.parseInt(scan.next());
	C = Integer.parseInt(scan.next());
	D = Integer.parseInt(scan.next());
	scan.close();
    }

    public final void answer() {
	int start = Integer.max(A, C);
	int end = Integer.min(B, D);
	int time = end - start;
	if(time < 0) time = 0;

	System.out.println(time);
    }
} public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final int A;
    private final int B;
    private final int C;
    private final int D;

    public Main() {
	A = Integer.parseInt(scan.next());
	B = Integer.parseInt(scan.next());
	C = Integer.parseInt(scan.next());
	D = Integer.parseInt(scan.next());
	scan.close();
    }

    public final void answer() {
	int start = Integer.max(A, C);
	int end = Integer.min(B, D);
	int time = end - start;
	if(time < 0) time = 0;

	System.out.println(time);
    }
} Main

import java.util.Scanner;

public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final int A;
    private final int B;
    private final int C;
    private final int D;

    public Main() {
	A = Integer.parseInt(scan.next());
	B = Integer.parseInt(scan.next());
	C = Integer.parseInt(scan.next());
	D = Integer.parseInt(scan.next());
	scan.close();
    }

    public final void answer() {
	int start = Integer.max(A, C);
	int end = Integer.min(B, D);
	int time = end - start;
	if(time < 0) time = 0;

	System.out.println(time);
    }
}
