import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {	
	
	public static void main(String[] args) throws NumberFormatException, IOException 
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}
	
	static class Task {
		
        public void solve(int testNumber, InputReader in, PrintWriter out) {

        	int a = in.nextInt();
        	int b = in.nextInt();
        	int c = in.nextInt();
        	int d = in.nextInt();
        	
        	if(b < c){
        		out.println(0);
        	}
        	else{
        		out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) );
        	}

        }
        
	}
	
	static class InputReader {
		
		BufferedReader in;
		StringTokenizer tok;
		
		public InputReader(InputStream stream){
			in = new BufferedReader(new InputStreamReader(stream), 32768);
			tok = null;
		}
		
		String nextToken() 
		{
			String line = "";
			while(tok == null || !tok.hasMoreTokens()) {
				try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
			}
			return tok.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(nextToken());
		}
		long nextLong()	{
			return Long.parseLong(nextToken());
		}
		double nextDouble()	{
			return Double.parseDouble(nextToken());
		}	
		
	}	
	
}





 import java.awt.*; awt.* java import java.awt.event.*; event.* java.awt import java.io.*; io.* java import java.math.*; math.* java import java.text.*; text.* java import java.util.*; util.* java public class Main {	
	
	public static void main(String[] args) throws NumberFormatException, IOException 
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}
	
	static class Task {
		
        public void solve(int testNumber, InputReader in, PrintWriter out) {

        	int a = in.nextInt();
        	int b = in.nextInt();
        	int c = in.nextInt();
        	int d = in.nextInt();
        	
        	if(b < c){
        		out.println(0);
        	}
        	else{
        		out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) );
        	}

        }
        
	}
	
	static class InputReader {
		
		BufferedReader in;
		StringTokenizer tok;
		
		public InputReader(InputStream stream){
			in = new BufferedReader(new InputStreamReader(stream), 32768);
			tok = null;
		}
		
		String nextToken() 
		{
			String line = "";
			while(tok == null || !tok.hasMoreTokens()) {
				try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
			}
			return tok.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(nextToken());
		}
		long nextLong()	{
			return Long.parseLong(nextToken());
		}
		double nextDouble()	{
			return Double.parseDouble(nextToken());
		}	
		
	}	
	
} Main public static void main(String[] args) throws NumberFormatException, IOException 
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	} main {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	} InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) Task solver = new Task(); solver new Task() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class Task {
		
        public void solve(int testNumber, InputReader in, PrintWriter out) {

        	int a = in.nextInt();
        	int b = in.nextInt();
        	int c = in.nextInt();
        	int d = in.nextInt();
        	
        	if(b < c){
        		out.println(0);
        	}
        	else{
        		out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) );
        	}

        }
        
	} Task public void solve(int testNumber, InputReader in, PrintWriter out) {

        	int a = in.nextInt();
        	int b = in.nextInt();
        	int c = in.nextInt();
        	int d = in.nextInt();
        	
        	if(b < c){
        		out.println(0);
        	}
        	else{
        		out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) );
        	}

        } solve {

        	int a = in.nextInt();
        	int b = in.nextInt();
        	int c = in.nextInt();
        	int d = in.nextInt();
        	
        	if(b < c){
        		out.println(0);
        	}
        	else{
        		out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) );
        	}

        } 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 if(b < c){
        		out.println(0);
        	}
        	else{
        		out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) );
        	} b < c b c {
        		out.println(0);
        	} out.println(0) out.println out 0 {
        		out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) );
        	} out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) ) out.println out Math.max(0 , Math.min(b, d) - Math.max(a, c) ) Math.max Math 0 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 int testNumber testNumber InputReader in in PrintWriter out out static class InputReader {
		
		BufferedReader in;
		StringTokenizer tok;
		
		public InputReader(InputStream stream){
			in = new BufferedReader(new InputStreamReader(stream), 32768);
			tok = null;
		}
		
		String nextToken() 
		{
			String line = "";
			while(tok == null || !tok.hasMoreTokens()) {
				try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
			}
			return tok.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(nextToken());
		}
		long nextLong()	{
			return Long.parseLong(nextToken());
		}
		double nextDouble()	{
			return Double.parseDouble(nextToken());
		}	
		
	} InputReader BufferedReader in; in StringTokenizer tok; tok public InputReader(InputStream stream){
			in = new BufferedReader(new InputStreamReader(stream), 32768);
			tok = null;
		} InputReader {
			in = new BufferedReader(new InputStreamReader(stream), 32768);
			tok = null;
		} in = new BufferedReader(new InputStreamReader(stream), 32768) in new BufferedReader(new InputStreamReader(stream), 32768) tok = null tok null InputStream stream stream String nextToken() 
		{
			String line = "";
			while(tok == null || !tok.hasMoreTokens()) {
				try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
			}
			return tok.nextToken();
		} nextToken {
			String line = "";
			while(tok == null || !tok.hasMoreTokens()) {
				try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
			}
			return tok.nextToken();
		} String line = ""; line "" while(tok == null || !tok.hasMoreTokens()) {
				try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
			} tok == null || !tok.hasMoreTokens() tok == null tok null !tok.hasMoreTokens() tok.hasMoreTokens() tok.hasMoreTokens tok {
				try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
			} try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				} IOException e {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				} e.printStackTrace() e.printStackTrace e return null; null {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null; (line = in.readLine()) != null (line = in.readLine()) line in.readLine() in.readLine in null tok = new StringTokenizer(line) tok new StringTokenizer(line) return null; null return tok.nextToken(); tok.nextToken() tok.nextToken tok int nextInt(){
			return Integer.parseInt(nextToken());
		} nextInt {
			return Integer.parseInt(nextToken());
		} return Integer.parseInt(nextToken()); Integer.parseInt(nextToken()) Integer.parseInt Integer nextToken() nextToken long nextLong()	{
			return Long.parseLong(nextToken());
		} nextLong {
			return Long.parseLong(nextToken());
		} return Long.parseLong(nextToken()); Long.parseLong(nextToken()) Long.parseLong Long nextToken() nextToken double nextDouble()	{
			return Double.parseDouble(nextToken());
		} nextDouble {
			return Double.parseDouble(nextToken());
		} return Double.parseDouble(nextToken()); Double.parseDouble(nextToken()) Double.parseDouble Double nextToken() nextToken public class Main {	
	
	public static void main(String[] args) throws NumberFormatException, IOException 
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}
	
	static class Task {
		
        public void solve(int testNumber, InputReader in, PrintWriter out) {

        	int a = in.nextInt();
        	int b = in.nextInt();
        	int c = in.nextInt();
        	int d = in.nextInt();
        	
        	if(b < c){
        		out.println(0);
        	}
        	else{
        		out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) );
        	}

        }
        
	}
	
	static class InputReader {
		
		BufferedReader in;
		StringTokenizer tok;
		
		public InputReader(InputStream stream){
			in = new BufferedReader(new InputStreamReader(stream), 32768);
			tok = null;
		}
		
		String nextToken() 
		{
			String line = "";
			while(tok == null || !tok.hasMoreTokens()) {
				try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
			}
			return tok.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(nextToken());
		}
		long nextLong()	{
			return Long.parseLong(nextToken());
		}
		double nextDouble()	{
			return Double.parseDouble(nextToken());
		}	
		
	}	
	
} public class Main {	
	
	public static void main(String[] args) throws NumberFormatException, IOException 
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}
	
	static class Task {
		
        public void solve(int testNumber, InputReader in, PrintWriter out) {

        	int a = in.nextInt();
        	int b = in.nextInt();
        	int c = in.nextInt();
        	int d = in.nextInt();
        	
        	if(b < c){
        		out.println(0);
        	}
        	else{
        		out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) );
        	}

        }
        
	}
	
	static class InputReader {
		
		BufferedReader in;
		StringTokenizer tok;
		
		public InputReader(InputStream stream){
			in = new BufferedReader(new InputStreamReader(stream), 32768);
			tok = null;
		}
		
		String nextToken() 
		{
			String line = "";
			while(tok == null || !tok.hasMoreTokens()) {
				try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
			}
			return tok.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(nextToken());
		}
		long nextLong()	{
			return Long.parseLong(nextToken());
		}
		double nextDouble()	{
			return Double.parseDouble(nextToken());
		}	
		
	}	
	
} Main
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {	
	
	public static void main(String[] args) throws NumberFormatException, IOException 
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}
	
	static class Task {
		
        public void solve(int testNumber, InputReader in, PrintWriter out) {

        	int a = in.nextInt();
        	int b = in.nextInt();
        	int c = in.nextInt();
        	int d = in.nextInt();
        	
        	if(b < c){
        		out.println(0);
        	}
        	else{
        		out.println(Math.max(0 , Math.min(b, d) - Math.max(a, c) ) );
        	}

        }
        
	}
	
	static class InputReader {
		
		BufferedReader in;
		StringTokenizer tok;
		
		public InputReader(InputStream stream){
			in = new BufferedReader(new InputStreamReader(stream), 32768);
			tok = null;
		}
		
		String nextToken() 
		{
			String line = "";
			while(tok == null || !tok.hasMoreTokens()) {
				try {
					if((line = in.readLine()) != null)
						tok = new StringTokenizer(line);
					else 
						return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
			}
			return tok.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(nextToken());
		}
		long nextLong()	{
			return Long.parseLong(nextToken());
		}
		double nextDouble()	{
			return Double.parseDouble(nextToken());
		}	
		
	}	
	
}






