import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int A,B,C,D;
	public void solve() {
		A = nextInt();
		B = nextInt();
		C = nextInt();
		D = nextInt();

		int ans = 0;
		if(A <= C && D <= B){
			ans = D - C;
		}else if(C <= A && B <= D){
			ans = B - A;
		}else if(B <= C || D <= A){
			ans = 0;
		}else{
			ans = Math.min(B, D) - Math.max(A,C);
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}
} import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.NoSuchElementException; NoSuchElementException java.util public class Main {
	int A,B,C,D;
	public void solve() {
		A = nextInt();
		B = nextInt();
		C = nextInt();
		D = nextInt();

		int ans = 0;
		if(A <= C && D <= B){
			ans = D - C;
		}else if(C <= A && B <= D){
			ans = B - A;
		}else if(B <= C || D <= A){
			ans = 0;
		}else{
			ans = Math.min(B, D) - Math.max(A,C);
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}
} Main int A A B B C C D; D /* Input */
	private static final InputStream in = System.in; in System.in System System.in private static final PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) private final byte[] buffer = new byte[2048]; buffer new byte[2048] 2048 private int p = 0; p 0 private int buflen = 0; buflen 0 public void solve() {
		A = nextInt();
		B = nextInt();
		C = nextInt();
		D = nextInt();

		int ans = 0;
		if(A <= C && D <= B){
			ans = D - C;
		}else if(C <= A && B <= D){
			ans = B - A;
		}else if(B <= C || D <= A){
			ans = 0;
		}else{
			ans = Math.min(B, D) - Math.max(A,C);
		}

		out.println(ans);
	} solve {
		A = nextInt();
		B = nextInt();
		C = nextInt();
		D = nextInt();

		int ans = 0;
		if(A <= C && D <= B){
			ans = D - C;
		}else if(C <= A && B <= D){
			ans = B - A;
		}else if(B <= C || D <= A){
			ans = 0;
		}else{
			ans = Math.min(B, D) - Math.max(A,C);
		}

		out.println(ans);
	} A = nextInt() A nextInt() nextInt B = nextInt() B nextInt() nextInt C = nextInt() C nextInt() nextInt D = nextInt() D nextInt() nextInt int ans = 0; ans 0 if(A <= C && D <= B){
			ans = D - C;
		}else if(C <= A && B <= D){
			ans = B - A;
		}else if(B <= C || D <= A){
			ans = 0;
		}else{
			ans = Math.min(B, D) - Math.max(A,C);
		} A <= C && D <= B A <= C A C D <= B D B {
			ans = D - C;
		} ans = D - C ans D - C D C if(C <= A && B <= D){
			ans = B - A;
		}else if(B <= C || D <= A){
			ans = 0;
		}else{
			ans = Math.min(B, D) - Math.max(A,C);
		} C <= A && B <= D C <= A C A B <= D B D {
			ans = B - A;
		} ans = B - A ans B - A B A if(B <= C || D <= A){
			ans = 0;
		}else{
			ans = Math.min(B, D) - Math.max(A,C);
		} B <= C || D <= A B <= C B C D <= A D A {
			ans = 0;
		} ans = 0 ans 0 {
			ans = Math.min(B, D) - Math.max(A,C);
		} ans = Math.min(B, D) - Math.max(A,C) ans Math.min(B, D) - Math.max(A,C) Math.min(B, D) Math.min Math B D Math.max(A,C) Math.max Math A C out.println(ans) out.println out ans public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	} main {
		out.flush();
		new Main().solve();
		out.close();
	} out.flush() out.flush out new Main().solve() new Main().solve new Main() out.close() out.close out String[] args args private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	} hasNextByte {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	} if (p < buflen)
			return true; p < buflen p buflen return true; true p = 0 p 0 try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			buflen = in.read(buffer);
		} buflen = in.read(buffer) buflen in.read(buffer) in.read in buffer if (buflen <= 0)
			return false; buflen <= 0 buflen 0 return false; false return true; true public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	} hasNext {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	} while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		} hasNextByte() && !isPrint(buffer[p]) hasNextByte() hasNextByte !isPrint(buffer[p]) isPrint(buffer[p]) isPrint buffer[p] buffer p {
			p++;
		} p++ p return hasNextByte(); hasNextByte() hasNextByte private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	} isPrint {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	} if (ch >= '!' && ch <= '~')
			return true; ch >= '!' && ch <= '~' ch >= '!' ch '!' ch <= '~' ch '~' return true; true return false; false int ch ch private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	} nextByte {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	} if (!hasNextByte())
			return -1; !hasNextByte() hasNextByte() hasNextByte return -1; -1 1 return buffer[p++]; buffer[p++] buffer p++ p public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	} next {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	} if (!hasNext())
			throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() StringBuilder sb = new StringBuilder(); sb new StringBuilder() int b = -1; b -1 1 while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		} isPrint((b = nextByte())) isPrint (b = nextByte()) b nextByte() nextByte {
			sb.appendCodePoint(b);
		} sb.appendCodePoint(b) sb.appendCodePoint sb b return sb.toString(); sb.toString() sb.toString sb public int nextInt() {
		return Integer.parseInt(next());
	} nextInt {
		return Integer.parseInt(next());
	} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong() {
		return Long.parseLong(next());
	} nextLong {
		return Long.parseLong(next());
	} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public double nextDouble() {
		return Double.parseDouble(next());
	} nextDouble {
		return Double.parseDouble(next());
	} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public class Main {
	int A,B,C,D;
	public void solve() {
		A = nextInt();
		B = nextInt();
		C = nextInt();
		D = nextInt();

		int ans = 0;
		if(A <= C && D <= B){
			ans = D - C;
		}else if(C <= A && B <= D){
			ans = B - A;
		}else if(B <= C || D <= A){
			ans = 0;
		}else{
			ans = Math.min(B, D) - Math.max(A,C);
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}
} public class Main {
	int A,B,C,D;
	public void solve() {
		A = nextInt();
		B = nextInt();
		C = nextInt();
		D = nextInt();

		int ans = 0;
		if(A <= C && D <= B){
			ans = D - C;
		}else if(C <= A && B <= D){
			ans = B - A;
		}else if(B <= C || D <= A){
			ans = 0;
		}else{
			ans = Math.min(B, D) - Math.max(A,C);
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}
} Main
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int A,B,C,D;
	public void solve() {
		A = nextInt();
		B = nextInt();
		C = nextInt();
		D = nextInt();

		int ans = 0;
		if(A <= C && D <= B){
			ans = D - C;
		}else if(C <= A && B <= D){
			ans = B - A;
		}else if(B <= C || D <= A){
			ans = 0;
		}else{
			ans = Math.min(B, D) - Math.max(A,C);
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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