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