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

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

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

  }

}
