
import java.io.*;
import java.util.*;

public class Main {
	static final int N=(int)5005;
    public static void main(String[] args) {  
        InputStream sys=System.in;
        InputReader in=new InputReader(sys);
        PrintWriter out=new PrintWriter(System.out);
        int A=in.nextInt(),B=in.nextInt();
        int C=in.nextInt(),D=in.nextInt();
        int ans=0;
        if(C>=B||A>=D) ans=0;
        else {
        	if(B>C&&C>A) ans+=B-C;
        	if(D>A&&A>C) ans+=D-A;
        }
        if(A<=C&&D<=B) ans=D-C;
        if(C<=A&&B<=D) ans=B-A;
        out.println(ans);
        out.flush();
    }
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
        
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
	static final int N=(int)5005;
    public static void main(String[] args) {  
        InputStream sys=System.in;
        InputReader in=new InputReader(sys);
        PrintWriter out=new PrintWriter(System.out);
        int A=in.nextInt(),B=in.nextInt();
        int C=in.nextInt(),D=in.nextInt();
        int ans=0;
        if(C>=B||A>=D) ans=0;
        else {
        	if(B>C&&C>A) ans+=B-C;
        	if(D>A&&A>C) ans+=D-A;
        }
        if(A<=C&&D<=B) ans=D-C;
        if(C<=A&&B<=D) ans=B-A;
        out.println(ans);
        out.flush();
    }
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
        
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
} Main static final int N=(int)5005; N (int)5005 public static void main(String[] args) {  
        InputStream sys=System.in;
        InputReader in=new InputReader(sys);
        PrintWriter out=new PrintWriter(System.out);
        int A=in.nextInt(),B=in.nextInt();
        int C=in.nextInt(),D=in.nextInt();
        int ans=0;
        if(C>=B||A>=D) ans=0;
        else {
        	if(B>C&&C>A) ans+=B-C;
        	if(D>A&&A>C) ans+=D-A;
        }
        if(A<=C&&D<=B) ans=D-C;
        if(C<=A&&B<=D) ans=B-A;
        out.println(ans);
        out.flush();
    } main {  
        InputStream sys=System.in;
        InputReader in=new InputReader(sys);
        PrintWriter out=new PrintWriter(System.out);
        int A=in.nextInt(),B=in.nextInt();
        int C=in.nextInt(),D=in.nextInt();
        int ans=0;
        if(C>=B||A>=D) ans=0;
        else {
        	if(B>C&&C>A) ans+=B-C;
        	if(D>A&&A>C) ans+=D-A;
        }
        if(A<=C&&D<=B) ans=D-C;
        if(C<=A&&B<=D) ans=B-A;
        out.println(ans);
        out.flush();
    } InputStream sys=System.in; sys System.in System System.in InputReader in=new InputReader(sys); in new InputReader(sys) PrintWriter out=new PrintWriter(System.out); out new PrintWriter(System.out) int A=in.nextInt() A in.nextInt() in.nextInt in B=in.nextInt(); B in.nextInt() in.nextInt in int C=in.nextInt() C in.nextInt() in.nextInt in D=in.nextInt(); D in.nextInt() in.nextInt in int ans=0; ans 0 if(C>=B||A>=D) ans=0;
        else {
        	if(B>C&&C>A) ans+=B-C;
        	if(D>A&&A>C) ans+=D-A;
        } C>=B||A>=D C>=B C B A>=D A D ans=0 ans 0 {
        	if(B>C&&C>A) ans+=B-C;
        	if(D>A&&A>C) ans+=D-A;
        } if(B>C&&C>A) ans+=B-C; B>C&&C>A B>C B C C>A C A ans+=B-C ans B-C B C if(D>A&&A>C) ans+=D-A; D>A&&A>C D>A D A A>C A C ans+=D-A ans D-A D A if(A<=C&&D<=B) ans=D-C; A<=C&&D<=B A<=C A C D<=B D B ans=D-C ans D-C D C if(C<=A&&B<=D) ans=B-A; C<=A&&B<=D C<=A C A B<=D B D ans=B-A ans B-A B A out.println(ans) out.println out ans out.flush() out.flush out String[] args args static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
        
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
	} InputReader public BufferedReader reader; reader public StringTokenizer tokenizer; tokenizer public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		} InputReader {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		} reader = new BufferedReader(new InputStreamReader(stream), 32768) reader new BufferedReader(new InputStreamReader(stream), 32768) tokenizer = null tokenizer null InputStream stream stream public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		} next {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		} while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			} tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			} try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				} catch (IOException e) {
					throw new RuntimeException(e);
				} IOException e {
					throw new RuntimeException(e);
				} throw new RuntimeException(e); new RuntimeException(e) {
					tokenizer = new StringTokenizer(reader.readLine());
				} tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer 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 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 {
	static final int N=(int)5005;
    public static void main(String[] args) {  
        InputStream sys=System.in;
        InputReader in=new InputReader(sys);
        PrintWriter out=new PrintWriter(System.out);
        int A=in.nextInt(),B=in.nextInt();
        int C=in.nextInt(),D=in.nextInt();
        int ans=0;
        if(C>=B||A>=D) ans=0;
        else {
        	if(B>C&&C>A) ans+=B-C;
        	if(D>A&&A>C) ans+=D-A;
        }
        if(A<=C&&D<=B) ans=D-C;
        if(C<=A&&B<=D) ans=B-A;
        out.println(ans);
        out.flush();
    }
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
        
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
} public class Main {
	static final int N=(int)5005;
    public static void main(String[] args) {  
        InputStream sys=System.in;
        InputReader in=new InputReader(sys);
        PrintWriter out=new PrintWriter(System.out);
        int A=in.nextInt(),B=in.nextInt();
        int C=in.nextInt(),D=in.nextInt();
        int ans=0;
        if(C>=B||A>=D) ans=0;
        else {
        	if(B>C&&C>A) ans+=B-C;
        	if(D>A&&A>C) ans+=D-A;
        }
        if(A<=C&&D<=B) ans=D-C;
        if(C<=A&&B<=D) ans=B-A;
        out.println(ans);
        out.flush();
    }
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
        
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
} Main

import java.io.*;
import java.util.*;

public class Main {
	static final int N=(int)5005;
    public static void main(String[] args) {  
        InputStream sys=System.in;
        InputReader in=new InputReader(sys);
        PrintWriter out=new PrintWriter(System.out);
        int A=in.nextInt(),B=in.nextInt();
        int C=in.nextInt(),D=in.nextInt();
        int ans=0;
        if(C>=B||A>=D) ans=0;
        else {
        	if(B>C&&C>A) ans+=B-C;
        	if(D>A&&A>C) ans+=D-A;
        }
        if(A<=C&&D<=B) ans=D-C;
        if(C<=A&&B<=D) ans=B-A;
        out.println(ans);
        out.flush();
    }
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
        
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}