import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int t = Math.min(b,d) - Math.max(a,c);
        if(t < 0) t = 0;
        System.out.println(t);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int t = Math.min(b,d) - Math.max(a,c);
        if(t < 0) t = 0;
        System.out.println(t);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int t = Math.min(b,d) - Math.max(a,c);
        if(t < 0) t = 0;
        System.out.println(t);
    } main {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int t = Math.min(b,d) - Math.max(a,c);
        if(t < 0) t = 0;
        System.out.println(t);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = Integer.parseInt(sc.next()); a Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int b = Integer.parseInt(sc.next()); b Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int c = Integer.parseInt(sc.next()); c Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int d = Integer.parseInt(sc.next()); d Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int t = Math.min(b,d) - Math.max(a,c); t 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 if(t < 0) t = 0; t < 0 t 0 t = 0 t 0 System.out.println(t) System.out.println System.out System System.out t String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int t = Math.min(b,d) - Math.max(a,c);
        if(t < 0) t = 0;
        System.out.println(t);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int t = Math.min(b,d) - Math.max(a,c);
        if(t < 0) t = 0;
        System.out.println(t);
    }
} Main
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int t = Math.min(b,d) - Math.max(a,c);
        if(t < 0) t = 0;
        System.out.println(t);
    }
}