import java.util.Scanner;

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

    public Main() {
        Scanner sc = new Scanner(System.in);
        int aStart = Integer.parseInt(sc.next());
        int aEnd = Integer.parseInt(sc.next());
        int bStart = Integer.parseInt(sc.next());
        int bEnd = Integer.parseInt(sc.next());
        int start = Math.max(aStart, bStart);
        int end = Math.min(aEnd, bEnd);
        int intersection = Math.max(0, end - start);
        System.out.println(intersection);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        new Main();
    }

    public Main() {
        Scanner sc = new Scanner(System.in);
        int aStart = Integer.parseInt(sc.next());
        int aEnd = Integer.parseInt(sc.next());
        int bStart = Integer.parseInt(sc.next());
        int bEnd = Integer.parseInt(sc.next());
        int start = Math.max(aStart, bStart);
        int end = Math.min(aEnd, bEnd);
        int intersection = Math.max(0, end - start);
        System.out.println(intersection);
    }
} Main public static void main(String[] args) {
        new Main();
    } main {
        new Main();
    } new Main() String[] args args public Main() {
        Scanner sc = new Scanner(System.in);
        int aStart = Integer.parseInt(sc.next());
        int aEnd = Integer.parseInt(sc.next());
        int bStart = Integer.parseInt(sc.next());
        int bEnd = Integer.parseInt(sc.next());
        int start = Math.max(aStart, bStart);
        int end = Math.min(aEnd, bEnd);
        int intersection = Math.max(0, end - start);
        System.out.println(intersection);
    } Main {
        Scanner sc = new Scanner(System.in);
        int aStart = Integer.parseInt(sc.next());
        int aEnd = Integer.parseInt(sc.next());
        int bStart = Integer.parseInt(sc.next());
        int bEnd = Integer.parseInt(sc.next());
        int start = Math.max(aStart, bStart);
        int end = Math.min(aEnd, bEnd);
        int intersection = Math.max(0, end - start);
        System.out.println(intersection);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int aStart = Integer.parseInt(sc.next()); aStart Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int aEnd = Integer.parseInt(sc.next()); aEnd Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int bStart = Integer.parseInt(sc.next()); bStart Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int bEnd = Integer.parseInt(sc.next()); bEnd Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int start = Math.max(aStart, bStart); start Math.max(aStart, bStart) Math.max Math aStart bStart int end = Math.min(aEnd, bEnd); end Math.min(aEnd, bEnd) Math.min Math aEnd bEnd int intersection = Math.max(0, end - start); intersection Math.max(0, end - start) Math.max Math 0 end - start end start System.out.println(intersection) System.out.println System.out System System.out intersection public class Main {
    public static void main(String[] args) {
        new Main();
    }

    public Main() {
        Scanner sc = new Scanner(System.in);
        int aStart = Integer.parseInt(sc.next());
        int aEnd = Integer.parseInt(sc.next());
        int bStart = Integer.parseInt(sc.next());
        int bEnd = Integer.parseInt(sc.next());
        int start = Math.max(aStart, bStart);
        int end = Math.min(aEnd, bEnd);
        int intersection = Math.max(0, end - start);
        System.out.println(intersection);
    }
} public class Main {
    public static void main(String[] args) {
        new Main();
    }

    public Main() {
        Scanner sc = new Scanner(System.in);
        int aStart = Integer.parseInt(sc.next());
        int aEnd = Integer.parseInt(sc.next());
        int bStart = Integer.parseInt(sc.next());
        int bEnd = Integer.parseInt(sc.next());
        int start = Math.max(aStart, bStart);
        int end = Math.min(aEnd, bEnd);
        int intersection = Math.max(0, end - start);
        System.out.println(intersection);
    }
} Main
import java.util.Scanner;

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

    public Main() {
        Scanner sc = new Scanner(System.in);
        int aStart = Integer.parseInt(sc.next());
        int aEnd = Integer.parseInt(sc.next());
        int bStart = Integer.parseInt(sc.next());
        int bEnd = Integer.parseInt(sc.next());
        int start = Math.max(aStart, bStart);
        int end = Math.min(aEnd, bEnd);
        int intersection = Math.max(0, end - start);
        System.out.println(intersection);
    }
}
