#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];

struct point {
	int x, begin;
	int ptr;
	point(int _x, int _begin) {
		x = _x;
		begin = _begin;		
	}
};
vector<point> up;
vector<point> down;

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;	
    	}
    }
    for (int i = 0; i < n; ++i)
    	up.pb(point(a1[i], 1)), up.pb(point(b1[i], 0));
	for (int i = 0; i < m; ++i)
    	down.pb(point(a2[i], 1)), down.pb(point(b2[i], 0));
}
int intersect(int a, int b) {
    int x = a2[b], y = b2[b];
    return max(min(b1[a], y) - max(a1[a], x), 0);
}

int find_ans() {
	int sum = 0;     
    for (int k = 0, y = 0; k < m;) {
        while (y < n && intersect(y, k) == 0 && b1[y] <= a2[k])
            ++y;
        int t = intersect(y, k);
        while (y < n && t > 0) {
        	sum += t;
        	++y;
        	t = intersect(y, k);        
       	} 
        --y;
        ++k;                    
    }
    return sum;	
}





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


void update(int y) {
   	if (down[y].begin) {
   		if (down[y].ptr == up.size() || up[down[y].ptr].begin)
   			add_sum -= 1;
   		else
   			add_sum += 1;    	
   	}
   	else {
   		if (down[y].ptr == up.size() || up[down[y].ptr].begin)
   			add_sum += 1;
   		else
   			add_sum -= 1;    	    	
   	}	

    ++down[y].ptr;
       
   	if (down[y].begin) {
   		if (down[y].ptr == up.size() || up[down[y].ptr].begin)
   			add_sum += 1;
   		else
   			add_sum -= 1;    	
   	}
   	else {
   		if (down[y].ptr == up.size() || up[down[y].ptr].begin)
   			add_sum -= 1;
   		else
   			add_sum += 1;    	    	
   	}	                                
       	
}
   

int main(){
    freopen(NAME ".in", "r", stdin); 
    freopen(NAME ".out", "w", stdout); 
    init();    
    for (int i = 0, y = 0; i < down.size(); ++i) {
    	while (y < up.size() && down[i].x >= up[y].x)
    		++y;	
    	down[i].ptr = y;
    }
    set<pair<int, int> > q;                                                                  
    for (int i = 0; i < down.size(); ++i) {
    	if (down[i].ptr < up.size())
    		q.insert(mp(up[down[i].ptr].x - down[i].x, i));
    }
    for (int i = 0; i < down.size(); i++) {
    	if (down[i].begin) {
    		if (down[i].ptr == up.size() || up[down[i].ptr].begin)
    			add_sum += 1;
    		else
    			add_sum -= 1;    	
    	}
    	else {
    		if (down[i].ptr == up.size() || up[down[i].ptr].begin)
    			add_sum -= 1;
    		else
    			add_sum += 1;    	    	
    	}	
    }    
    
    int max_d = r - b2[m - 1];
    int sum = find_ans();    
    int d = 0, ans = sum;    
    while (q.size() > 0) {
    	pi now = *q.begin();    	
    	int y = now.second;    	   		
    	int now_d = up[down[y].ptr].x - down[y].x - d;
    	if (d + now_d >= max_d)
    		break;    	
    	sum += (add_sum / 2) * now_d;    	    	
    	d += now_d;    	    	
    	update(y);
        ans = max(ans, sum);       	
       	q.erase(now);       	
       	if (down[y].ptr < up.size())
       		q.insert(mp(up[down[y].ptr].x - down[y].x, y));    
    }    
    int s = 0;
    for (int i = 0; i < m; ++i)
        s += b2[i] - a2[i];             		
   	printf("%d", max(0, s - ans));      
    return 0;
}
