import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;

public class Main {
    FastScanner in = new FastScanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

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

    int calcTime(int A, int B, int C, int D) {
        // C <-> DがA <-> Bの範囲と重複しない場合
        if (B <= C || D <= A) {
            return 0;
        }
    
        // CがAより小さい場合
        if (C < A) {
            // DがB以下なら，A<->Dが重複範囲となる
            if (D <= B) {
                return D - A;
            }
            // DがBより大きければ，A<->Bが重複範囲となる
            else {
                return B - A;
            }
        }
        // 残るケースはCがAとBの間にある場合のみ
        else {
            // DがB以下なら，C<->Dが重複範囲となる
            if (D <= B) {
                return D - C;
            }
            // DがBより大きければ，C<->Bが重複範囲となる
            else {
                return B - C;
            }
            
        }

    }
    
    public void calc() {
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        int D = in.nextInt();

        out.println(calcTime(A, B, C, D));
        out.close();
    }
    
    class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = nextInt();

            return array;
        }

        int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextIntArray(m);
            }
            return map;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++)
                array[i] = nextLong();

            return array;
        }

        long[][] nextLongMap(int n, int m) {
            long[][] map = new long[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextLongArray(m);
            }
            return map;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++)
                array[i] = nextDouble();

            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextDoubleArray(m);
            }
            return map;
        }

        String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++)
                array[i] = next();

            return array;
        }

        String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
} import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.ArrayList; ArrayList java.util import java.util.HashMap; HashMap java.util import java.util.InputMismatchException; InputMismatchException java.util import java.util.List; List java.util import java.util.Map; Map java.util public class Main {
    FastScanner in = new FastScanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

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

    int calcTime(int A, int B, int C, int D) {
        // C <-> DがA <-> Bの範囲と重複しない場合
        if (B <= C || D <= A) {
            return 0;
        }
    
        // CがAより小さい場合
        if (C < A) {
            // DがB以下なら，A<->Dが重複範囲となる
            if (D <= B) {
                return D - A;
            }
            // DがBより大きければ，A<->Bが重複範囲となる
            else {
                return B - A;
            }
        }
        // 残るケースはCがAとBの間にある場合のみ
        else {
            // DがB以下なら，C<->Dが重複範囲となる
            if (D <= B) {
                return D - C;
            }
            // DがBより大きければ，C<->Bが重複範囲となる
            else {
                return B - C;
            }
            
        }

    }
    
    public void calc() {
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        int D = in.nextInt();

        out.println(calcTime(A, B, C, D));
        out.close();
    }
    
    class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = nextInt();

            return array;
        }

        int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextIntArray(m);
            }
            return map;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++)
                array[i] = nextLong();

            return array;
        }

        long[][] nextLongMap(int n, int m) {
            long[][] map = new long[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextLongArray(m);
            }
            return map;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++)
                array[i] = nextDouble();

            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextDoubleArray(m);
            }
            return map;
        }

        String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++)
                array[i] = next();

            return array;
        }

        String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
} Main FastScanner in = new FastScanner(System.in); in new FastScanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) public static void main(String[] args) {
        new Main().calc();
    } main {
        new Main().calc();
    } new Main().calc() new Main().calc new Main() String[] args args int calcTime(int A, int B, int C, int D) {
        // C <-> DがA <-> Bの範囲と重複しない場合
        if (B <= C || D <= A) {
            return 0;
        }
    
        // CがAより小さい場合
        if (C < A) {
            // DがB以下なら，A<->Dが重複範囲となる
            if (D <= B) {
                return D - A;
            }
            // DがBより大きければ，A<->Bが重複範囲となる
            else {
                return B - A;
            }
        }
        // 残るケースはCがAとBの間にある場合のみ
        else {
            // DがB以下なら，C<->Dが重複範囲となる
            if (D <= B) {
                return D - C;
            }
            // DがBより大きければ，C<->Bが重複範囲となる
            else {
                return B - C;
            }
            
        }

    } calcTime {
        // C <-> DがA <-> Bの範囲と重複しない場合
        if (B <= C || D <= A) {
            return 0;
        }
    
        // CがAより小さい場合
        if (C < A) {
            // DがB以下なら，A<->Dが重複範囲となる
            if (D <= B) {
                return D - A;
            }
            // DがBより大きければ，A<->Bが重複範囲となる
            else {
                return B - A;
            }
        }
        // 残るケースはCがAとBの間にある場合のみ
        else {
            // DがB以下なら，C<->Dが重複範囲となる
            if (D <= B) {
                return D - C;
            }
            // DがBより大きければ，C<->Bが重複範囲となる
            else {
                return B - C;
            }
            
        }

    } if (B <= C || D <= A) {
            return 0;
        } B <= C || D <= A B <= C B C D <= A D A {
            return 0;
        } return 0; 0 if (C < A) {
            // DがB以下なら，A<->Dが重複範囲となる
            if (D <= B) {
                return D - A;
            }
            // DがBより大きければ，A<->Bが重複範囲となる
            else {
                return B - A;
            }
        }
        // 残るケースはCがAとBの間にある場合のみ
        else {
            // DがB以下なら，C<->Dが重複範囲となる
            if (D <= B) {
                return D - C;
            }
            // DがBより大きければ，C<->Bが重複範囲となる
            else {
                return B - C;
            }
            
        } C < A C A {
            // DがB以下なら，A<->Dが重複範囲となる
            if (D <= B) {
                return D - A;
            }
            // DがBより大きければ，A<->Bが重複範囲となる
            else {
                return B - A;
            }
        } if (D <= B) {
                return D - A;
            }
            // DがBより大きければ，A<->Bが重複範囲となる
            else {
                return B - A;
            } D <= B D B {
                return D - A;
            } return D - A; D - A D A {
                return B - A;
            } return B - A; B - A B A {
            // DがB以下なら，C<->Dが重複範囲となる
            if (D <= B) {
                return D - C;
            }
            // DがBより大きければ，C<->Bが重複範囲となる
            else {
                return B - C;
            }
            
        } if (D <= B) {
                return D - C;
            }
            // DがBより大きければ，C<->Bが重複範囲となる
            else {
                return B - C;
            } D <= B D B {
                return D - C;
            } return D - C; D - C D C {
                return B - C;
            } return B - C; B - C B C int A A int B B int C C int D D public void calc() {
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        int D = in.nextInt();

        out.println(calcTime(A, B, C, D));
        out.close();
    } calc {
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        int D = in.nextInt();

        out.println(calcTime(A, B, C, D));
        out.close();
    } 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 out.println(calcTime(A, B, C, D)) out.println out calcTime(A, B, C, D) calcTime A B C D out.close() out.close out class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = nextInt();

            return array;
        }

        int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextIntArray(m);
            }
            return map;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++)
                array[i] = nextLong();

            return array;
        }

        long[][] nextLongMap(int n, int m) {
            long[][] map = new long[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextLongArray(m);
            }
            return map;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++)
                array[i] = nextDouble();

            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextDoubleArray(m);
            }
            return map;
        }

        String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++)
                array[i] = next();

            return array;
        }

        String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    } FastScanner private InputStream stream; stream private byte[] buf = new byte[1024]; buf new byte[1024] 1024 private int curChar; curChar private int numChars; numChars public FastScanner(InputStream stream) {
            this.stream = stream;
        } FastScanner {
            this.stream = stream;
        } this.stream = stream this.stream this this.stream stream InputStream stream stream int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        } read {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        } if (numChars == -1)
                throw new InputMismatchException(); numChars == -1 numChars -1 1 throw new InputMismatchException(); new InputMismatchException() if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            } curChar >= numChars curChar numChars {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            } curChar = 0 curChar 0 try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                } catch (IOException e) {
                    throw new InputMismatchException();
                } IOException e {
                    throw new InputMismatchException();
                } throw new InputMismatchException(); new InputMismatchException() {
                    numChars = stream.read(buf);
                } numChars = stream.read(buf) numChars stream.read(buf) stream.read stream buf if (numChars <= 0)
                    return -1; numChars <= 0 numChars 0 return -1; -1 1 return buf[curChar++]; buf[curChar++] buf curChar++ curChar boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        } isSpaceChar {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        } return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1 c == '\t' c == '\r' c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1 c == ' ' c ' ' c == '\n' c '\n' c == '\r' c '\r' c == '\t' c '\t' c == -1 c -1 1 int c c boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        } isEndline {
            return c == '\n' || c == '\r' || c == -1;
        } return c == '\n' || c == '\r' || c == -1; c == '\n' || c == '\r' || c == -1 c == '\n' || c == '\r' || c == -1 c == '\n' c '\n' c == '\r' c '\r' c == -1 c -1 1 int c c int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = nextInt();

            return array;
        } nextIntArray {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = nextInt();

            return array;
        } int[] array = new int[n]; array new int[n] n for (int i = 0; i < n; i++)
                array[i] = nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i array[i] = nextInt(); array[i] = nextInt() array[i] array i nextInt() nextInt return array; array int n n int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextIntArray(m);
            }
            return map;
        } nextIntMap {
            int[][] map = new int[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextIntArray(m);
            }
            return map;
        } int[][] map = new int[n][m]; map new int[n][m] n m for (int i = 0; i < n; i++) {
                map[i] = in.nextIntArray(m);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                map[i] = in.nextIntArray(m);
            } {
                map[i] = in.nextIntArray(m);
            } map[i] = in.nextIntArray(m) map[i] map i in.nextIntArray(m) in.nextIntArray in m return map; map int n n int m m long nextLong() {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++)
                array[i] = nextLong();

            return array;
        } nextLongArray {
            long[] array = new long[n];
            for (int i = 0; i < n; i++)
                array[i] = nextLong();

            return array;
        } long[] array = new long[n]; array new long[n] n for (int i = 0; i < n; i++)
                array[i] = nextLong(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i array[i] = nextLong(); array[i] = nextLong() array[i] array i nextLong() nextLong return array; array int n n long[][] nextLongMap(int n, int m) {
            long[][] map = new long[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextLongArray(m);
            }
            return map;
        } nextLongMap {
            long[][] map = new long[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextLongArray(m);
            }
            return map;
        } long[][] map = new long[n][m]; map new long[n][m] n m for (int i = 0; i < n; i++) {
                map[i] = in.nextLongArray(m);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                map[i] = in.nextLongArray(m);
            } {
                map[i] = in.nextLongArray(m);
            } map[i] = in.nextLongArray(m) map[i] map i in.nextLongArray(m) in.nextLongArray in m return map; map int n n int m m double nextDouble() {
            return Double.parseDouble(next());
        } nextDouble {
            return Double.parseDouble(next());
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++)
                array[i] = nextDouble();

            return array;
        } nextDoubleArray {
            double[] array = new double[n];
            for (int i = 0; i < n; i++)
                array[i] = nextDouble();

            return array;
        } double[] array = new double[n]; array new double[n] n for (int i = 0; i < n; i++)
                array[i] = nextDouble(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i array[i] = nextDouble(); array[i] = nextDouble() array[i] array i nextDouble() nextDouble return array; array int n n double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextDoubleArray(m);
            }
            return map;
        } nextDoubleMap {
            double[][] map = new double[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextDoubleArray(m);
            }
            return map;
        } double[][] map = new double[n][m]; map new double[n][m] n m for (int i = 0; i < n; i++) {
                map[i] = in.nextDoubleArray(m);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                map[i] = in.nextDoubleArray(m);
            } {
                map[i] = in.nextDoubleArray(m);
            } map[i] = in.nextDoubleArray(m) map[i] map i in.nextDoubleArray(m) in.nextDoubleArray in m return map; map int n n int m m String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        } next {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        } int c = read(); c read() read while (isSpaceChar(c))
                c = read(); isSpaceChar(c) isSpaceChar c c = read() c read() read StringBuilder res = new StringBuilder(); res new StringBuilder() do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
                res.appendCodePoint(c);
                c = read();
            } res.appendCodePoint(c) res.appendCodePoint res c c = read() c read() read return res.toString(); res.toString() res.toString res String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++)
                array[i] = next();

            return array;
        } nextStringArray {
            String[] array = new String[n];
            for (int i = 0; i < n; i++)
                array[i] = next();

            return array;
        } String[] array = new String[n]; array new String[n] n for (int i = 0; i < n; i++)
                array[i] = next(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i array[i] = next(); array[i] = next() array[i] array i next() next return array; array int n n String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        } nextLine {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        } int c = read(); c read() read while (isEndline(c))
                c = read(); isEndline(c) isEndline c c = read() c read() read StringBuilder res = new StringBuilder(); res new StringBuilder() do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c)); !isEndline(c) isEndline(c) isEndline c {
                res.appendCodePoint(c);
                c = read();
            } res.appendCodePoint(c) res.appendCodePoint res c c = read() c read() read return res.toString(); res.toString() res.toString res public class Main {
    FastScanner in = new FastScanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

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

    int calcTime(int A, int B, int C, int D) {
        // C <-> DがA <-> Bの範囲と重複しない場合
        if (B <= C || D <= A) {
            return 0;
        }
    
        // CがAより小さい場合
        if (C < A) {
            // DがB以下なら，A<->Dが重複範囲となる
            if (D <= B) {
                return D - A;
            }
            // DがBより大きければ，A<->Bが重複範囲となる
            else {
                return B - A;
            }
        }
        // 残るケースはCがAとBの間にある場合のみ
        else {
            // DがB以下なら，C<->Dが重複範囲となる
            if (D <= B) {
                return D - C;
            }
            // DがBより大きければ，C<->Bが重複範囲となる
            else {
                return B - C;
            }
            
        }

    }
    
    public void calc() {
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        int D = in.nextInt();

        out.println(calcTime(A, B, C, D));
        out.close();
    }
    
    class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = nextInt();

            return array;
        }

        int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextIntArray(m);
            }
            return map;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++)
                array[i] = nextLong();

            return array;
        }

        long[][] nextLongMap(int n, int m) {
            long[][] map = new long[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextLongArray(m);
            }
            return map;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++)
                array[i] = nextDouble();

            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextDoubleArray(m);
            }
            return map;
        }

        String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++)
                array[i] = next();

            return array;
        }

        String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
} public class Main {
    FastScanner in = new FastScanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

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

    int calcTime(int A, int B, int C, int D) {
        // C <-> DがA <-> Bの範囲と重複しない場合
        if (B <= C || D <= A) {
            return 0;
        }
    
        // CがAより小さい場合
        if (C < A) {
            // DがB以下なら，A<->Dが重複範囲となる
            if (D <= B) {
                return D - A;
            }
            // DがBより大きければ，A<->Bが重複範囲となる
            else {
                return B - A;
            }
        }
        // 残るケースはCがAとBの間にある場合のみ
        else {
            // DがB以下なら，C<->Dが重複範囲となる
            if (D <= B) {
                return D - C;
            }
            // DがBより大きければ，C<->Bが重複範囲となる
            else {
                return B - C;
            }
            
        }

    }
    
    public void calc() {
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        int D = in.nextInt();

        out.println(calcTime(A, B, C, D));
        out.close();
    }
    
    class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = nextInt();

            return array;
        }

        int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextIntArray(m);
            }
            return map;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++)
                array[i] = nextLong();

            return array;
        }

        long[][] nextLongMap(int n, int m) {
            long[][] map = new long[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextLongArray(m);
            }
            return map;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++)
                array[i] = nextDouble();

            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextDoubleArray(m);
            }
            return map;
        }

        String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++)
                array[i] = next();

            return array;
        }

        String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
} Main
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;

public class Main {
    FastScanner in = new FastScanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

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

    int calcTime(int A, int B, int C, int D) {
        // C <-> DがA <-> Bの範囲と重複しない場合
        if (B <= C || D <= A) {
            return 0;
        }
    
        // CがAより小さい場合
        if (C < A) {
            // DがB以下なら，A<->Dが重複範囲となる
            if (D <= B) {
                return D - A;
            }
            // DがBより大きければ，A<->Bが重複範囲となる
            else {
                return B - A;
            }
        }
        // 残るケースはCがAとBの間にある場合のみ
        else {
            // DがB以下なら，C<->Dが重複範囲となる
            if (D <= B) {
                return D - C;
            }
            // DがBより大きければ，C<->Bが重複範囲となる
            else {
                return B - C;
            }
            
        }

    }
    
    public void calc() {
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        int D = in.nextInt();

        out.println(calcTime(A, B, C, D));
        out.close();
    }
    
    class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = nextInt();

            return array;
        }

        int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextIntArray(m);
            }
            return map;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++)
                array[i] = nextLong();

            return array;
        }

        long[][] nextLongMap(int n, int m) {
            long[][] map = new long[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextLongArray(m);
            }
            return map;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++)
                array[i] = nextDouble();

            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextDoubleArray(m);
            }
            return map;
        }

        String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++)
                array[i] = next();

            return array;
        }

        String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
}
