#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;
	}
	int mn = l - b[0].first;
	int mx = r - b[m - 1].second;
	ll ans = 1e18;

	for (int shift = mn; shift <= mx; shift++) {
	 	ll res = 0;
		for (int i = 0; i < n; i++) {
		 	for (int j = 0; j < m; j++) {
		 	 	int l1 = a[i].first, r1 = a[i].second;
				int l2 = b[j].first + shift, r2 = b[j].second + shift;
				res += max(min(r1, r2) - max(l1, l2), 0);
			}
		}
		ans = min(ans, res);
	}

	cout << ans << endl;	

	return 0;
}