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();
    int ans;
    if(a <= c){
      if(d <= b){
        ans = d - c;
      }else{
        ans = b - c;
      }
    }else{
      if(d <= b){
        ans = d - a;
      }else{
        ans = b - a;
      }
    }
    System.out.println(Math.max(ans, 0));
  }
} 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();
    int ans;
    if(a <= c){
      if(d <= b){
        ans = d - c;
      }else{
        ans = b - c;
      }
    }else{
      if(d <= b){
        ans = d - a;
      }else{
        ans = b - a;
      }
    }
    System.out.println(Math.max(ans, 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();
    int ans;
    if(a <= c){
      if(d <= b){
        ans = d - c;
      }else{
        ans = b - c;
      }
    }else{
      if(d <= b){
        ans = d - a;
      }else{
        ans = b - a;
      }
    }
    System.out.println(Math.max(ans, 0));
  } main {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int ans;
    if(a <= c){
      if(d <= b){
        ans = d - c;
      }else{
        ans = b - c;
      }
    }else{
      if(d <= b){
        ans = d - a;
      }else{
        ans = b - a;
      }
    }
    System.out.println(Math.max(ans, 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 int ans; ans if(a <= c){
      if(d <= b){
        ans = d - c;
      }else{
        ans = b - c;
      }
    }else{
      if(d <= b){
        ans = d - a;
      }else{
        ans = b - a;
      }
    } a <= c a c {
      if(d <= b){
        ans = d - c;
      }else{
        ans = b - c;
      }
    } if(d <= b){
        ans = d - c;
      }else{
        ans = b - c;
      } d <= b d b {
        ans = d - c;
      } ans = d - c ans d - c d c {
        ans = b - c;
      } ans = b - c ans b - c b c {
      if(d <= b){
        ans = d - a;
      }else{
        ans = b - a;
      }
    } if(d <= b){
        ans = d - a;
      }else{
        ans = b - a;
      } d <= b d b {
        ans = d - a;
      } ans = d - a ans d - a d a {
        ans = b - a;
      } ans = b - a ans b - a b a System.out.println(Math.max(ans, 0)) System.out.println System.out System System.out Math.max(ans, 0) Math.max Math ans 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();
    int ans;
    if(a <= c){
      if(d <= b){
        ans = d - c;
      }else{
        ans = b - c;
      }
    }else{
      if(d <= b){
        ans = d - a;
      }else{
        ans = b - a;
      }
    }
    System.out.println(Math.max(ans, 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();
    int ans;
    if(a <= c){
      if(d <= b){
        ans = d - c;
      }else{
        ans = b - c;
      }
    }else{
      if(d <= b){
        ans = d - a;
      }else{
        ans = b - a;
      }
    }
    System.out.println(Math.max(ans, 0));
  }
} Main
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();
    int ans;
    if(a <= c){
      if(d <= b){
        ans = d - c;
      }else{
        ans = b - c;
      }
    }else{
      if(d <= b){
        ans = d - a;
      }else{
        ans = b - a;
      }
    }
    System.out.println(Math.max(ans, 0));
  }
}
