#include<iostream>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (b > c) {
		if (b < d) {
			if (a > c) {
				cout << b - a;
			}
			else {
				cout << b - c;
			}
		}
		else {
			if (a > c) {
				cout << d - a;
			}
			else {
				cout << d - c;
			}
		}
	}
	else {
		cout << 0;
	}
	return 0;
}
