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



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();

    //c<<b<<d
    if(c <= b && b <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(c-b)) );
    }
    //c<<a<<d
    else if(c <= a && a <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(a-d)) );
    }
    //a<<c<<d<<b
    else if(a < c && d < b){
      System.out.println( Math.abs(d-c) );
    }else{
      System.out.println(0);
    }
  }
} import java.io.*; io.* java import java.util.*; util.* java 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();

    //c<<b<<d
    if(c <= b && b <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(c-b)) );
    }
    //c<<a<<d
    else if(c <= a && a <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(a-d)) );
    }
    //a<<c<<d<<b
    else if(a < c && d < b){
      System.out.println( Math.abs(d-c) );
    }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();

    //c<<b<<d
    if(c <= b && b <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(c-b)) );
    }
    //c<<a<<d
    else if(c <= a && a <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(a-d)) );
    }
    //a<<c<<d<<b
    else if(a < c && d < b){
      System.out.println( Math.abs(d-c) );
    }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();

    //c<<b<<d
    if(c <= b && b <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(c-b)) );
    }
    //c<<a<<d
    else if(c <= a && a <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(a-d)) );
    }
    //a<<c<<d<<b
    else if(a < c && d < b){
      System.out.println( Math.abs(d-c) );
    }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(c <= b && b <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(c-b)) );
    }
    //c<<a<<d
    else if(c <= a && a <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(a-d)) );
    }
    //a<<c<<d<<b
    else if(a < c && d < b){
      System.out.println( Math.abs(d-c) );
    }else{
      System.out.println(0);
    } c <= b && b <= d c <= b c b b <= d b d {
      System.out.println( Math.min(Math.abs(a-b), Math.abs(c-b)) );
    } System.out.println( Math.min(Math.abs(a-b), Math.abs(c-b)) ) System.out.println System.out System System.out Math.min(Math.abs(a-b), Math.abs(c-b)) Math.min Math Math.abs(a-b) Math.abs Math a-b a b Math.abs(c-b) Math.abs Math c-b c b if(c <= a && a <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(a-d)) );
    }
    //a<<c<<d<<b
    else if(a < c && d < b){
      System.out.println( Math.abs(d-c) );
    }else{
      System.out.println(0);
    } c <= a && a <= d c <= a c a a <= d a d {
      System.out.println( Math.min(Math.abs(a-b), Math.abs(a-d)) );
    } System.out.println( Math.min(Math.abs(a-b), Math.abs(a-d)) ) System.out.println System.out System System.out Math.min(Math.abs(a-b), Math.abs(a-d)) Math.min Math Math.abs(a-b) Math.abs Math a-b a b Math.abs(a-d) Math.abs Math a-d a d if(a < c && d < b){
      System.out.println( Math.abs(d-c) );
    }else{
      System.out.println(0);
    } a < c && d < b a < c a c d < b d b {
      System.out.println( Math.abs(d-c) );
    } System.out.println( Math.abs(d-c) ) System.out.println System.out System System.out Math.abs(d-c) Math.abs Math d-c d c {
      System.out.println(0);
    } System.out.println(0) System.out.println System.out System System.out 0 String[] args args
import java.io.*;
import java.util.*;



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();

    //c<<b<<d
    if(c <= b && b <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(c-b)) );
    }
    //c<<a<<d
    else if(c <= a && a <= d){
      System.out.println( Math.min(Math.abs(a-b), Math.abs(a-d)) );
    }
    //a<<c<<d<<b
    else if(a < c && d < b){
      System.out.println( Math.abs(d-c) );
    }else{
      System.out.println(0);
    }
  }
}
