#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int maxn = 333;

typedef long long ll;

int n, m, l, r;
pair<int, int> a[maxn], b[maxn];

int len(pair<int, int> a) {
 	return a.second - a.first;
}

int main() {
 	freopen("opposition.in", "r", stdin);
	freopen("opposition.out", "w", stdout);

	cin >> n >> m >> l >> r;
	for (int i = 0; i < n; i++) {
	 	cin >> a[i].first >> a[i].second;
	}
	for (int i = 0; i < m; i++) {
	 	cin >> b[i].first >> b[i].second;
	}

	// let's shift segments of second type

	vector<pair<int, int> > e;
	for (int i = 0; i < n; i++) {
	 	for (int j = 0; j < m; j++) {
			// shift by a[i].first - b[j].second will give last zero
			// shift by a[i].first - b[j].second + min(a[i].len, b[j].len) will give first +len
			// shift by a[i].second - b[j].first - min(a[i].len, b[j].len) will give last +len
			// shift by a[i].second - b[j].first will give first zero

			e.push_back(make_pair(a[i].first - b[j].second, 0));
			e.push_back(make_pair(a[i].first - b[j].second + min(len(a[i]), len(b[j])), 1));
			e.push_back(make_pair(a[i].second - b[j].first - min(len(a[i]), len(b[j])), 2));
			e.push_back(make_pair(a[i].second - b[j].first, 3));
		}
	}
	int mn = l - b[0].first;
	int mx = r - b[m - 1].second;
	for (int i = 0; i < 4; i++) e.push_back(make_pair(mn, i)); // min possible shift
	for (int i = 0; i < 4; i++) e.push_back(make_pair(mx, i)); // max possible shift
	
	sort(e.begin(), e.end());
	int curAdd = 0;
	ll curAns = 0;
	ll ans = 1e18;

	//cout << mn << " " << mx << endl;
	for (int i = 0; i < (int)e.size(); i++) {
		//cout << e[i].first << " " << curAns << endl;
		curAns += curAdd * (e[i].first - (i ? e[i - 1].first : 0));
		if (e[i].first >= mn && e[i].first <= mx) ans = min(ans, curAns);
	 	if (e[i].second == 0) {
			curAdd++;
		}
		if (e[i].second == 1) {
			curAdd--;
		}
		if (e[i].second == 2) {
			curAdd--;
		}
		if (e[i].second == 3) {
			curAdd++;
		}
	}
	cout << ans << endl;	

	return 0;
}