#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<vector> 
#include<cstring>
#include<string>
#include<map>
#include<set>
#define mp make_pair
#define scn second
#define frs first
#define pb push_back

#define NAME "opposition"

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pi;
int n, m, l, r;
int a1[500], a2[500], b1[500], b2[500];


void init() {
	scanf("%d%d%d%d", &n, &m, &l, &r);
    int last = l;    
    for (int i = 0; i < n; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        a1[i] = last;
        b1[i] = x;
        last = y;
    }
    a1[n] = last;
    b1[n] = r;
    ++n;
            
    for (int i = 0; i < m; ++i)                
        scanf("%d%d", &a2[i], &b2[i]);    	
    
    {
    	int tmp = l - a2[0];
    	for (int i = 0; i < m; ++i) {
    		a2[i] += tmp;
    		b2[i] += tmp;	
    	}
    }
}

int s = 0;
    
int intersect(int a, int b, int add) {
	add = 0;
    int x = a2[b] + add, y = b2[b] + add;
    return max(min(b1[a], y) - max(a1[a], x), 0);
}

int find_ans(int add) {
	if (add < 0 || b2[m - 1] + add > r)
		return 0;
	int sum = 0;	
	for (int i = 0; i < m; ++i)
    	a2[i] += add, b2[i] += add;
   	
   	for (int i = 0; i < m; ++i) {
   		int a = upper_bound(b1, b1 + n, a2[i]) - b1;   		
   		int b = lower_bound(a1, a1 + n, b2[i]) - a1;
   		for (int j = a; j < b; ++j)
   			sum += intersect(j, i, add);
   	}
    for (int i = 0; i < m; ++i)
    	a2[i] -= add, b2[i] -= add;   	
    return sum;	

}


int ans_add = 0;
int ans_sum = 0;
int add_sum = 0;
    
   

int main(){
    freopen(NAME ".in", "r", stdin); 
    freopen(NAME ".out", "w", stdout); 
    init();    
    int ans = 0;
    for (int i = 0; i < m; ++i)
        s += b2[i] - a2[i];             		
   	for (int i = 0; i < n; ++i) {
    	for (int j = 0; j < m; ++j) {
    		ans = max(ans, find_ans(a1[i] - a2[j]));
			ans = max(ans, find_ans(b1[i] - b2[j]));
    	}
    }        
    printf("%d", s - ans);      
    return 0;
}
