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

public class Main {
  private static int solve(int a, int b, int c, int d) {
    int maxBeginTime = Math.max(a, c);
    int minEndTime = Math.min(b, d);
    return Math.max(0, minEndTime - maxBeginTime);
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    int c = reader.nextInt();
    int d = reader.nextInt();
    out.println(solve(a, b, c, d));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
  private static int solve(int a, int b, int c, int d) {
    int maxBeginTime = Math.max(a, c);
    int minEndTime = Math.min(b, d);
    return Math.max(0, minEndTime - maxBeginTime);
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    int c = reader.nextInt();
    int d = reader.nextInt();
    out.println(solve(a, b, c, d));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
} Main private static int solve(int a, int b, int c, int d) {
    int maxBeginTime = Math.max(a, c);
    int minEndTime = Math.min(b, d);
    return Math.max(0, minEndTime - maxBeginTime);
  } solve {
    int maxBeginTime = Math.max(a, c);
    int minEndTime = Math.min(b, d);
    return Math.max(0, minEndTime - maxBeginTime);
  } int maxBeginTime = Math.max(a, c); maxBeginTime Math.max(a, c) Math.max Math a c int minEndTime = Math.min(b, d); minEndTime Math.min(b, d) Math.min Math b d return Math.max(0, minEndTime - maxBeginTime); Math.max(0, minEndTime - maxBeginTime) Math.max Math 0 minEndTime - maxBeginTime minEndTime maxBeginTime int a a int b b int c c int d d private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    int c = reader.nextInt();
    int d = reader.nextInt();
    out.println(solve(a, b, c, d));
  } execute {
    int a = reader.nextInt();
    int b = reader.nextInt();
    int c = reader.nextInt();
    int d = reader.nextInt();
    out.println(solve(a, b, c, d));
  } int a = reader.nextInt(); a reader.nextInt() reader.nextInt reader int b = reader.nextInt(); b reader.nextInt() reader.nextInt reader int c = reader.nextInt(); c reader.nextInt() reader.nextInt reader int d = reader.nextInt(); d reader.nextInt() reader.nextInt reader out.println(solve(a, b, c, d)) out.println out solve(a, b, c, d) solve a b c d ContestReader reader reader PrintWriter out out public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  } main {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  } ContestReader reader = new ContestReader(System.in); reader new ContestReader(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) execute(reader, out) execute reader out out.flush() out.flush out String[] args args class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
} ContestReader private BufferedReader reader; reader private StringTokenizer tokenizer; tokenizer ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  } ContestReader {
    reader = new BufferedReader(new InputStreamReader(in));
  } reader = new BufferedReader(new InputStreamReader(in)) reader new BufferedReader(new InputStreamReader(in)) InputStream in in public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  } next {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  } while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    } try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      } catch (Exception e) {
        throw new RuntimeException(e);
      } Exception e {
        throw new RuntimeException(e);
      } throw new RuntimeException(e); new RuntimeException(e) {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } tokenizer = new java.util.StringTokenizer(reader.readLine()) tokenizer new java.util.StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public int nextInt() {
    return Integer.parseInt(next());
  } nextInt {
    return Integer.parseInt(next());
  } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong() {
    return Long.parseLong(next());
  } nextLong {
    return Long.parseLong(next());
  } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public double nextDouble() {
    return Double.parseDouble(next());
  } nextDouble {
    return Double.parseDouble(next());
  } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  } next {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  } String[] array = new String[n]; array new String[n] n for (int i = 0; i < n; i++) {
      array[i] = next();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      array[i] = next();
    } {
      array[i] = next();
    } array[i] = next() array[i] array i next() next return array; array int n n public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  } nextInt {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  } int[] array = new int[n]; array new int[n] n for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      array[i] = nextInt();
    } {
      array[i] = nextInt();
    } array[i] = nextInt() array[i] array i nextInt() nextInt return array; array int n n public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  } nextLong {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  } long[] array = new long[n]; array new long[n] n for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      array[i] = nextLong();
    } {
      array[i] = nextLong();
    } array[i] = nextLong() array[i] array i nextLong() nextLong return array; array int n n public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  } nextDouble {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  } double[] array = new double[n]; array new double[n] n for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      array[i] = nextDouble();
    } {
      array[i] = nextDouble();
    } array[i] = nextDouble() array[i] array i nextDouble() nextDouble return array; array int n n public char[] nextCharArray() {
    return next().toCharArray();
  } nextCharArray {
    return next().toCharArray();
  } return next().toCharArray(); next().toCharArray() next().toCharArray next() next public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  } nextInt {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  } int[][] matrix = new int[n][m]; matrix new int[n][m] n m for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    } {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    } for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      } int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
        matrix[i][j] = nextInt();
      } {
        matrix[i][j] = nextInt();
      } matrix[i][j] = nextInt() matrix[i][j] matrix[i] matrix i j nextInt() nextInt return matrix; matrix int n n int m m public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  } nextLong {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  } long[][] matrix = new long[n][m]; matrix new long[n][m] n m for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    } {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    } for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      } int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
        matrix[i][j] = nextLong();
      } {
        matrix[i][j] = nextLong();
      } matrix[i][j] = nextLong() matrix[i][j] matrix[i] matrix i j nextLong() nextLong return matrix; matrix int n n int m m public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  } nextDouble {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  } double[][] matrix = new double[n][m]; matrix new double[n][m] n m for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    } {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    } for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      } int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
        matrix[i][j] = nextDouble();
      } {
        matrix[i][j] = nextDouble();
      } matrix[i][j] = nextDouble() matrix[i][j] matrix[i] matrix i j nextDouble() nextDouble return matrix; matrix int n n int m m public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  } nextCharArray {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  } char[][] matrix = new char[n][]; matrix new char[n][] n for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      matrix[i] = next().toCharArray();
    } {
      matrix[i] = next().toCharArray();
    } matrix[i] = next().toCharArray() matrix[i] matrix i next().toCharArray() next().toCharArray next() next return matrix; matrix int n n public class Main {
  private static int solve(int a, int b, int c, int d) {
    int maxBeginTime = Math.max(a, c);
    int minEndTime = Math.min(b, d);
    return Math.max(0, minEndTime - maxBeginTime);
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    int c = reader.nextInt();
    int d = reader.nextInt();
    out.println(solve(a, b, c, d));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
} public class Main {
  private static int solve(int a, int b, int c, int d) {
    int maxBeginTime = Math.max(a, c);
    int minEndTime = Math.min(b, d);
    return Math.max(0, minEndTime - maxBeginTime);
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    int c = reader.nextInt();
    int d = reader.nextInt();
    out.println(solve(a, b, c, d));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
} Main
import java.io.*;
import java.util.*;

public class Main {
  private static int solve(int a, int b, int c, int d) {
    int maxBeginTime = Math.max(a, c);
    int minEndTime = Math.min(b, d);
    return Math.max(0, minEndTime - maxBeginTime);
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    int c = reader.nextInt();
    int d = reader.nextInt();
    out.println(solve(a, b, c, d));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}
