import java.util.*;
import java.io.*;
public class Main {
	public static boolean[] b;
	static int[] FF;
	static int[] A;
	public static void main(String[] ard)  throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);
		String[] s=br.readLine().trim().split("\\s++");
		int a=Integer.valueOf(s[0]);
		int b=Integer.valueOf(s[1]);
		int c=Integer.valueOf(s[2]);
		int d=Integer.valueOf(s[3]);
		int upper=Math.min(b,d);
                int lower=Math.max(a,c);
                 pw.println(Math.max(0,upper-lower));
		
	pw.close();
		
	}
	 static long solve(int[] A, int k){
	       //int[] sum=new int[A.length+k+1];
	     ///  for(int i=1;i<=A.length;i++)
		 int n=A.length-1;
	       long ans=0;
	      /// Arrays.sort(A);
	       for(int i=1;i<=n-k+1;i++)
	       {
	           ans=Math.max(ans,Math.abs(A[i]-A[i+k-1]));
	       }
	       
	       return ans;
	    }
	public static boolean palin(String s)
	{
	   int i=0;
	   int j=s.length()-1;
	   while(i<j)
	   {
		   if(s.charAt(i)==s.charAt(j))
		   {
			   i++;
			   j--;
		   }
		   else return false;     
	   }
	   return true;
	}
	
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
	public static boolean[] b;
	static int[] FF;
	static int[] A;
	public static void main(String[] ard)  throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);
		String[] s=br.readLine().trim().split("\\s++");
		int a=Integer.valueOf(s[0]);
		int b=Integer.valueOf(s[1]);
		int c=Integer.valueOf(s[2]);
		int d=Integer.valueOf(s[3]);
		int upper=Math.min(b,d);
                int lower=Math.max(a,c);
                 pw.println(Math.max(0,upper-lower));
		
	pw.close();
		
	}
	 static long solve(int[] A, int k){
	       //int[] sum=new int[A.length+k+1];
	     ///  for(int i=1;i<=A.length;i++)
		 int n=A.length-1;
	       long ans=0;
	      /// Arrays.sort(A);
	       for(int i=1;i<=n-k+1;i++)
	       {
	           ans=Math.max(ans,Math.abs(A[i]-A[i+k-1]));
	       }
	       
	       return ans;
	    }
	public static boolean palin(String s)
	{
	   int i=0;
	   int j=s.length()-1;
	   while(i<j)
	   {
		   if(s.charAt(i)==s.charAt(j))
		   {
			   i++;
			   j--;
		   }
		   else return false;     
	   }
	   return true;
	}
	
} Main public static boolean[] b; b static int[] FF; FF static int[] A; A public static void main(String[] ard)  throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);
		String[] s=br.readLine().trim().split("\\s++");
		int a=Integer.valueOf(s[0]);
		int b=Integer.valueOf(s[1]);
		int c=Integer.valueOf(s[2]);
		int d=Integer.valueOf(s[3]);
		int upper=Math.min(b,d);
                int lower=Math.max(a,c);
                 pw.println(Math.max(0,upper-lower));
		
	pw.close();
		
	} main {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);
		String[] s=br.readLine().trim().split("\\s++");
		int a=Integer.valueOf(s[0]);
		int b=Integer.valueOf(s[1]);
		int c=Integer.valueOf(s[2]);
		int d=Integer.valueOf(s[3]);
		int upper=Math.min(b,d);
                int lower=Math.max(a,c);
                 pw.println(Math.max(0,upper-lower));
		
	pw.close();
		
	} BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) PrintWriter pw=new PrintWriter(System.out); pw new PrintWriter(System.out) String[] s=br.readLine().trim().split("\\s++"); s br.readLine().trim().split("\\s++") br.readLine().trim().split br.readLine().trim() br.readLine().trim br.readLine() br.readLine br "\\s++" int a=Integer.valueOf(s[0]); a Integer.valueOf(s[0]) Integer.valueOf Integer s[0] s 0 int b=Integer.valueOf(s[1]); b Integer.valueOf(s[1]) Integer.valueOf Integer s[1] s 1 int c=Integer.valueOf(s[2]); c Integer.valueOf(s[2]) Integer.valueOf Integer s[2] s 2 int d=Integer.valueOf(s[3]); d Integer.valueOf(s[3]) Integer.valueOf Integer s[3] s 3 int upper=Math.min(b,d); upper Math.min(b,d) Math.min Math b d int lower=Math.max(a,c); lower Math.max(a,c) Math.max Math a c pw.println(Math.max(0,upper-lower)) pw.println pw Math.max(0,upper-lower) Math.max Math 0 upper-lower upper lower pw.close() pw.close pw String[] ard ard static long solve(int[] A, int k){
	       //int[] sum=new int[A.length+k+1];
	     ///  for(int i=1;i<=A.length;i++)
		 int n=A.length-1;
	       long ans=0;
	      /// Arrays.sort(A);
	       for(int i=1;i<=n-k+1;i++)
	       {
	           ans=Math.max(ans,Math.abs(A[i]-A[i+k-1]));
	       }
	       
	       return ans;
	    } solve {
	       //int[] sum=new int[A.length+k+1];
	     ///  for(int i=1;i<=A.length;i++)
		 int n=A.length-1;
	       long ans=0;
	      /// Arrays.sort(A);
	       for(int i=1;i<=n-k+1;i++)
	       {
	           ans=Math.max(ans,Math.abs(A[i]-A[i+k-1]));
	       }
	       
	       return ans;
	    } int n=A.length-1; n A.length-1 A.length A A.length 1 long ans=0; ans 0 for(int i=1;i<=n-k+1;i++)
	       {
	           ans=Math.max(ans,Math.abs(A[i]-A[i+k-1]));
	       } int i=1; int i=1; i 1 i<=n-k+1 i n-k+1 n-k n k 1 i++ i++ i {
	           ans=Math.max(ans,Math.abs(A[i]-A[i+k-1]));
	       } {
	           ans=Math.max(ans,Math.abs(A[i]-A[i+k-1]));
	       } ans=Math.max(ans,Math.abs(A[i]-A[i+k-1])) ans Math.max(ans,Math.abs(A[i]-A[i+k-1])) Math.max Math ans Math.abs(A[i]-A[i+k-1]) Math.abs Math A[i]-A[i+k-1] A[i] A i A[i+k-1] A i+k-1 i+k i k 1 return ans; ans int[] A A int k k public static boolean palin(String s)
	{
	   int i=0;
	   int j=s.length()-1;
	   while(i<j)
	   {
		   if(s.charAt(i)==s.charAt(j))
		   {
			   i++;
			   j--;
		   }
		   else return false;     
	   }
	   return true;
	} palin {
	   int i=0;
	   int j=s.length()-1;
	   while(i<j)
	   {
		   if(s.charAt(i)==s.charAt(j))
		   {
			   i++;
			   j--;
		   }
		   else return false;     
	   }
	   return true;
	} int i=0; i 0 int j=s.length()-1; j s.length()-1 s.length() s.length s 1 while(i<j)
	   {
		   if(s.charAt(i)==s.charAt(j))
		   {
			   i++;
			   j--;
		   }
		   else return false;     
	   } i<j i j {
		   if(s.charAt(i)==s.charAt(j))
		   {
			   i++;
			   j--;
		   }
		   else return false;     
	   } if(s.charAt(i)==s.charAt(j))
		   {
			   i++;
			   j--;
		   }
		   else return false; s.charAt(i)==s.charAt(j) s.charAt(i) s.charAt s i s.charAt(j) s.charAt s j {
			   i++;
			   j--;
		   } i++ i j-- j return false; false return true; true String s s public class Main {
	public static boolean[] b;
	static int[] FF;
	static int[] A;
	public static void main(String[] ard)  throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);
		String[] s=br.readLine().trim().split("\\s++");
		int a=Integer.valueOf(s[0]);
		int b=Integer.valueOf(s[1]);
		int c=Integer.valueOf(s[2]);
		int d=Integer.valueOf(s[3]);
		int upper=Math.min(b,d);
                int lower=Math.max(a,c);
                 pw.println(Math.max(0,upper-lower));
		
	pw.close();
		
	}
	 static long solve(int[] A, int k){
	       //int[] sum=new int[A.length+k+1];
	     ///  for(int i=1;i<=A.length;i++)
		 int n=A.length-1;
	       long ans=0;
	      /// Arrays.sort(A);
	       for(int i=1;i<=n-k+1;i++)
	       {
	           ans=Math.max(ans,Math.abs(A[i]-A[i+k-1]));
	       }
	       
	       return ans;
	    }
	public static boolean palin(String s)
	{
	   int i=0;
	   int j=s.length()-1;
	   while(i<j)
	   {
		   if(s.charAt(i)==s.charAt(j))
		   {
			   i++;
			   j--;
		   }
		   else return false;     
	   }
	   return true;
	}
	
} public class Main {
	public static boolean[] b;
	static int[] FF;
	static int[] A;
	public static void main(String[] ard)  throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);
		String[] s=br.readLine().trim().split("\\s++");
		int a=Integer.valueOf(s[0]);
		int b=Integer.valueOf(s[1]);
		int c=Integer.valueOf(s[2]);
		int d=Integer.valueOf(s[3]);
		int upper=Math.min(b,d);
                int lower=Math.max(a,c);
                 pw.println(Math.max(0,upper-lower));
		
	pw.close();
		
	}
	 static long solve(int[] A, int k){
	       //int[] sum=new int[A.length+k+1];
	     ///  for(int i=1;i<=A.length;i++)
		 int n=A.length-1;
	       long ans=0;
	      /// Arrays.sort(A);
	       for(int i=1;i<=n-k+1;i++)
	       {
	           ans=Math.max(ans,Math.abs(A[i]-A[i+k-1]));
	       }
	       
	       return ans;
	    }
	public static boolean palin(String s)
	{
	   int i=0;
	   int j=s.length()-1;
	   while(i<j)
	   {
		   if(s.charAt(i)==s.charAt(j))
		   {
			   i++;
			   j--;
		   }
		   else return false;     
	   }
	   return true;
	}
	
} Main
import java.util.*;
import java.io.*;
public class Main {
	public static boolean[] b;
	static int[] FF;
	static int[] A;
	public static void main(String[] ard)  throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);
		String[] s=br.readLine().trim().split("\\s++");
		int a=Integer.valueOf(s[0]);
		int b=Integer.valueOf(s[1]);
		int c=Integer.valueOf(s[2]);
		int d=Integer.valueOf(s[3]);
		int upper=Math.min(b,d);
                int lower=Math.max(a,c);
                 pw.println(Math.max(0,upper-lower));
		
	pw.close();
		
	}
	 static long solve(int[] A, int k){
	       //int[] sum=new int[A.length+k+1];
	     ///  for(int i=1;i<=A.length;i++)
		 int n=A.length-1;
	       long ans=0;
	      /// Arrays.sort(A);
	       for(int i=1;i<=n-k+1;i++)
	       {
	           ans=Math.max(ans,Math.abs(A[i]-A[i+k-1]));
	       }
	       
	       return ans;
	    }
	public static boolean palin(String s)
	{
	   int i=0;
	   int j=s.length()-1;
	   while(i<j)
	   {
		   if(s.charAt(i)==s.charAt(j))
		   {
			   i++;
			   j--;
		   }
		   else return false;     
	   }
	   return true;
	}
	
}