import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if(a<=c&&b<=d&&c<=b){
      System.out.println(b-c);
    }else if(c<=a&&d<=b&&a<=d){
      System.out.println(d-a);
    }else if(a<=c&&a<=d&&b>=c&&b>=d){
      System.out.println(d-c);
    }else if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    }
  }
} import java.util.Arrays; Arrays java.util import java.util.*; util.* java public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if(a<=c&&b<=d&&c<=b){
      System.out.println(b-c);
    }else if(c<=a&&d<=b&&a<=d){
      System.out.println(d-a);
    }else if(a<=c&&a<=d&&b>=c&&b>=d){
      System.out.println(d-c);
    }else if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    }
  }
} Main public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if(a<=c&&b<=d&&c<=b){
      System.out.println(b-c);
    }else if(c<=a&&d<=b&&a<=d){
      System.out.println(d-a);
    }else if(a<=c&&a<=d&&b>=c&&b>=d){
      System.out.println(d-c);
    }else if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if(a<=c&&b<=d&&c<=b){
      System.out.println(b-c);
    }else if(c<=a&&d<=b&&a<=d){
      System.out.println(d-a);
    }else if(a<=c&&a<=d&&b>=c&&b>=d){
      System.out.println(d-c);
    }else if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc if(a<=c&&b<=d&&c<=b){
      System.out.println(b-c);
    }else if(c<=a&&d<=b&&a<=d){
      System.out.println(d-a);
    }else if(a<=c&&a<=d&&b>=c&&b>=d){
      System.out.println(d-c);
    }else if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    } a<=c&&b<=d&&c<=b a<=c&&b<=d&&c<=b a<=c a c b<=d b d c<=b c b {
      System.out.println(b-c);
    } System.out.println(b-c) System.out.println System.out System System.out b-c b c if(c<=a&&d<=b&&a<=d){
      System.out.println(d-a);
    }else if(a<=c&&a<=d&&b>=c&&b>=d){
      System.out.println(d-c);
    }else if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    } c<=a&&d<=b&&a<=d c<=a&&d<=b&&a<=d c<=a c a d<=b d b a<=d a d {
      System.out.println(d-a);
    } System.out.println(d-a) System.out.println System.out System System.out d-a d a if(a<=c&&a<=d&&b>=c&&b>=d){
      System.out.println(d-c);
    }else if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    } a<=c&&a<=d&&b>=c&&b>=d b>=c a<=c&&a<=d&&b>=c&&b>=d a<=c a c a<=d a d b>=c b c b>=d b d {
      System.out.println(d-c);
    } System.out.println(d-c) System.out.println System.out System System.out d-c d c if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    } c<=a&&c<=b&&d>=a&&d>=b d>=a c<=a&&c<=b&&d>=a&&d>=b c<=a c a c<=b c b d>=a d a d>=b d b {
      System.out.println(b-a);
    } System.out.println(b-a) System.out.println System.out System System.out b-a b a {
      System.out.println(0);
    } System.out.println(0) System.out.println System.out System System.out 0 String args[] args public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if(a<=c&&b<=d&&c<=b){
      System.out.println(b-c);
    }else if(c<=a&&d<=b&&a<=d){
      System.out.println(d-a);
    }else if(a<=c&&a<=d&&b>=c&&b>=d){
      System.out.println(d-c);
    }else if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    }
  }
} public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if(a<=c&&b<=d&&c<=b){
      System.out.println(b-c);
    }else if(c<=a&&d<=b&&a<=d){
      System.out.println(d-a);
    }else if(a<=c&&a<=d&&b>=c&&b>=d){
      System.out.println(d-c);
    }else if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    }
  }
} Main
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if(a<=c&&b<=d&&c<=b){
      System.out.println(b-c);
    }else if(c<=a&&d<=b&&a<=d){
      System.out.println(d-a);
    }else if(a<=c&&a<=d&&b>=c&&b>=d){
      System.out.println(d-c);
    }else if(c<=a&&c<=b&&d>=a&&d>=b){
      System.out.println(b-a);
    }else{
      System.out.println(0);
    }
  }
}
