import java.util.Scanner;

import static java.lang.Math.max;
import static java.lang.Math.min;

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

    private
    void run()
    {
        Scanner in = new Scanner(System.in);

        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        int left = max(c, a);
        int right = min(b, d);

        System.out.println(right - left > 0 ? right - left : 0);
    }
} import java.util.Scanner; Scanner java.util import static java.lang.Math.max; import static java.lang.Math.max; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.min; import static java.lang.Math.min; class Main
{
    public static
    void main(String[] args)
    {
        new Main().run();
    }

    private
    void run()
    {
        Scanner in = new Scanner(System.in);

        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        int left = max(c, a);
        int right = min(b, d);

        System.out.println(right - left > 0 ? right - left : 0);
    }
} Main 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()
    {
        Scanner in = new Scanner(System.in);

        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        int left = max(c, a);
        int right = min(b, d);

        System.out.println(right - left > 0 ? right - left : 0);
    } run {
        Scanner in = new Scanner(System.in);

        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        int left = max(c, a);
        int right = min(b, d);

        System.out.println(right - left > 0 ? right - left : 0);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int a = in.nextInt(); a in.nextInt() in.nextInt in int b = in.nextInt(); b in.nextInt() in.nextInt in int c = in.nextInt(); c in.nextInt() in.nextInt in int d = in.nextInt(); d in.nextInt() in.nextInt in int left = max(c, a); left max(c, a) max c a int right = min(b, d); right min(b, d) min b d System.out.println(right - left > 0 ? right - left : 0) System.out.println System.out System System.out right - left > 0 ? right - left : 0 right - left > 0 right - left right left 0 right - left right left 0 class Main
{
    public static
    void main(String[] args)
    {
        new Main().run();
    }

    private
    void run()
    {
        Scanner in = new Scanner(System.in);

        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        int left = max(c, a);
        int right = min(b, d);

        System.out.println(right - left > 0 ? right - left : 0);
    }
} class Main
{
    public static
    void main(String[] args)
    {
        new Main().run();
    }

    private
    void run()
    {
        Scanner in = new Scanner(System.in);

        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        int left = max(c, a);
        int right = min(b, d);

        System.out.println(right - left > 0 ? right - left : 0);
    }
} Main
import java.util.Scanner;

import static java.lang.Math.max;
import static java.lang.Math.min;

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

    private
    void run()
    {
        Scanner in = new Scanner(System.in);

        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        int left = max(c, a);
        int right = min(b, d);

        System.out.println(right - left > 0 ? right - left : 0);
    }
}
