Little X and Little Z are good friends. They always chat online. But both of them have schedules.

Little Z has fixed schedule. He always online at any moment of time between a1 and b1, between a2 and b2, ..., between ap and bp (all borders inclusive). But the schedule of Little X is quite strange, it depends on the time when he gets up. If he gets up at time 0, he will be online at any moment of time between c1 and d1, between c2 and d2, ..., between cq and dq (all borders inclusive). But if he gets up at time t, these segments will be shifted by t. They become [ci + t, di + t] (for all i).

If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of time between l and r (both borders inclusive). Also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules). How many integer moments of time from the segment [l, r] suit for that?

Input

The first line contains four space-separated integers p, q, l, r (1 ≤ p, q ≤ 50; 0 ≤ l ≤ r ≤ 1000).

Each of the next p lines contains two space-separated integers ai, bi (0 ≤ ai < bi ≤ 1000). Each of the next q lines contains two space-separated integers cj, dj (0 ≤ cj < dj ≤ 1000).

It's guaranteed that bi < ai + 1 and dj < cj + 1 for all valid i and j.

Output

Output a single integer — the number of moments of time from the segment [l, r] which suit for online conversation.

Examples

Input

1 1 0 4
2 3
0 1


Output

3


Input

2 3 0 20
15 17
23 26
1 4
7 11
15 17


Output

20
import java.io.*;
import java.util.*;

public class A {
	
	
	public static void main(String[] args){
    	FastReader();
		int t = 1;
		while(t>0)
		{
			
			solve();
			
			--t;
		}
		write.flush();
		write.close();
	}
	
    static void solve()
	{
    	int p=ni(),q=ni(),l=ni(),r=ni();
    	List<Interval> z=new ArrayList<>();
    	List<Interval> x=new ArrayList<>();
    	
    	for(int i=0;i<p;++i)
    	{
    		int a=ni();
    		int b=ni();
    		Interval k=new Interval(a,b);
    		z.add(k);
    	}
    	
    	for(int i=0;i<q;++i)
    	{
    		int a=ni();
    		int b=ni();
    		Interval k=new Interval(a,b);
    		x.add(k);
    	}
    	
    	Set<Integer> a= new HashSet<>();
    	Set<Integer> b= new HashSet<>();
    	
    	for(int i=0;i<p;++i)
    	{
    		for(int j=z.get(i).a;j<=z.get(i).b;++j)
    		{
    			a.add(j);
    		}
    	}
    	
    	for(int i=0;i<q;++i)
    	{
    		for(int j=x.get(i).a;j<=x.get(i).b;++j)
    		{
    			b.add(j);
    		}
    	}
    	int count=0;
    	for(int i=l;i<=r;++i)
    	{
    		Set<Integer> c= new HashSet<>(a);
    		Set<Integer> d= new HashSet<>();
    		for(int e:b)
    		{
    			d.add(e+i);
    		}
    		d.retainAll(c);
    		
    		if(d.size()>0)
    		{
    			++count;
    		}
    	}
    	
    	out(count);
    	
    	
    	
	    
	}
    
    public static class Interval
    {
    	Integer a;
    	Integer b;
    	
    	public Interval(int a ,int b)
    	{
    		this.a=a;
    		this.b=b;
    	}
    }
    
    //NECESSARY FUNCTIONS
    
    
    
    
	
											//CONSTANTS//
    static final int MOD = (int) 1e9 + 7;
	
											//INPUT//
    
	static BufferedReader br; 
    static StringTokenizer st;
    
    public static void FastReader() 
    { 
        br = new BufferedReader(new
                 InputStreamReader(System.in)); 
    } 
    
    //STRING INPUT
    static String nx()           
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    
    //STRING(WITH SPACES) INPUT
    static String nln()    		
    { 
        String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
    
    //INTEGER INPUT
    static int ni()             
    { 
        return Integer.parseInt(nx()); 
    } 
    
    //LONG INPUT
    static long nl() 			
    { 
        return Long.parseLong(nx()); 
    } 
    
    //DOUBLE INPUT
    static double nd()			 
    { 
        return Double.parseDouble(nx()); 
    } 

    //ARRAY INPUT
    static int[] ina(int n) 	
    {
		int[] temp = new int[n];
		
		for (int i = 0; i < n; i++) 
		{
			temp[i] = ni();
		}
		
		return temp;
	}
    
    //LONG ARRAY INPUT
    static long[] inal(int n) 	
    {
		long[] temp = new long[n];
		
		for (int i = 0; i < n; i++) 
		{
			temp[i] = ni();
		}
		
		return temp;
	}
    
    										//OUTPUT//
    
    static PrintWriter write= new PrintWriter(System.out);
    
    //OUTPUT NEXTLINE
    static void out()	
    { 
        write.println();
    }
    
    //ARRAY OUTPUT WITH NEXTLINE
    static void out(int[] ar) 	
    { 
        for(int e: ar)
        {
        	write.print(e+" ");
        }
        write.println();
    } 
    
    //LONG ARRAY OUTPUT WITH NEXTLINE
    static void out(long[] ar) 	
    { 
        for(long e: ar)
        {
        	write.print(e+" ");
        }
        write.println();
    }
    
    //OBJECT OUTPUT WITH NEXTLINE
    static void out(Object obj)	
    { 
        write.println(obj);
    }
    
    //ARRAY OUTPUT WITHOUT NEXTLINE
    static void ou(int[] ar)	
    { 
        for(int e: ar)
        {
        	write.print(e+" ");
        }
    }
    
    //LONG ARRAY OUTPUT WITH NEXTLINE
    static void ou(long[] ar) 	
    { 
        for(long e: ar)
        {
        	write.print(e+" ");
        }
    }
    
    //OBJECT INPUT WITHOUT NEXTLINE
    static void ou(Object obj)	
    { 
        write.print(obj);
    }
    
    										//SEARCHING ALGORITHMS//
    
    //BINARY SEARCH
    static int bs(int arr[], int x) 
    { 
        int l = 0, r = arr.length - 1; 
        while (l <= r) { 
            int m = l + (r - l) / 2; 
            if (arr[m] == x) 
                return m; 
            if (arr[m] < x) 
                l = m + 1; 
            else
                r = m - 1; 
        } 
        return -1; 
    }
    
    static int bs(long arr[], int x) 
    { 
        int l = 0, r = arr.length - 1; 
        while (l <= r) { 
            int m = l + (r - l) / 2;  
            if (arr[m] == x) 
                return m; 
            if (arr[m] < x) 
                l = m + 1; 
            else
                r = m - 1; 
        } 
        return -1; 
    }
    
    										//SORTING ALGORITHMS//
    
    //MERGE SORT
    static void sort(int arr[], int l, int m, int r)
    {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int[n1];
        int R[] = new int[n2];
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            }
            else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
 
    static void merge(int arr[], int l, int r)
    {
        if (l < r) {
            int m =l+ (r-l)/2;
            merge(arr, l, m);
            merge(arr, m + 1, r);
            sort(arr, l, m, r);
        }
    }
    
    //BUBBLE SORT
    static void bubble(int arr[]) 
    { 
        int n = arr.length; 
        for (int i = 0; i < n-1; i++)
        {
            for (int j = 0; j < n-i-1; j++)
            {
                if (arr[j] > arr[j+1]) 
                {
                    int temp = arr[j]; 
                    arr[j] = arr[j+1]; 
                    arr[j+1] = temp; 
                } 
            }
        }
    }
    
    										//OTHER FUNCTIONS//
    
    //FUNCTION TO COUNT NO. OF DIGITS
    static int countDigit(long n)
    {
        int count = 0;
        while (n != 0) {
            n = n / 10;
            ++count;
        }
        return count;
    }
    
    //FUNCTION TO CALCULATE SUM OF DIGITS
    static int sumOfDigits(int n) 
    {     
        int sum = 0;   
        while (n != 0) 
        { 
            sum = sum + n % 10; 
            n = n/10; 
        } 
        return sum; 
    }
    
    //FUNCTION TO FIND SUM OF ARRAY ELEMENTS
    static long arraySum(int[] arr , int start , int end)
    {
        long sum = 0 ;
        for(int i = start ; i <= end  ; ++i)
        {
        	sum = sum + arr[i] ;
        }
        return sum  ;
    }
    
    //FUNCTION TO CALCULATE FACTORIAL
    static int fact(int n) 
    { 
        if (n == 0) 
          return 1; 
        return n*fact(n-1); 
    }
    
    //FUNCTION TO CHECK POWER OF TWO
    static boolean isPowerOfTwo(int n)
    {
        if(n==0)
        return false;
        return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == 
           (int)(Math.floor(((Math.log(n) / Math.log(2)))));
    }
    
    //FUNCTION TO REVERSE A STRING
    static String reverse(String str)
    {
    	StringBuilder input = new StringBuilder();
        input.append(str);
        input.reverse();
        return input.toString();
    }
    
    //FUNCTION TO CALCULATE GCD
    public static int gcd(int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b%a, a);
    }
    
    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b%a, a);
    }
    
    //FUNCTION TO CALCULATE LCM
    static int lcm(int a, int b) 
    { 
        return (a / gcd(a, b)) * b; 
    }
    
    static long lcm(long a, long b) 
    { 
        return (a / gcd(a, b)) * b; 
    }
    
    //FUNCTION TO CHECK PRIME OR NOT
    static boolean isPrime(int n) 
    { 
        if (n <= 1) 
            return false; 
        if (n <= 3) 
            return true; 
        if (n % 2 == 0 || n % 3 == 0) 
            return false; 
        for (int i = 5; i * i <= n; i = i + 6) 
            if (n % i == 0 || n % (i + 2) == 0) 
                return false; 
        return true; 
    }
    
    //FUNCTION TO CALCULATE NCR    
    static long nCr(int n, int r) 
    { 
        return fact(n) / (fact(r) * 
                      fact(n - r)); 
    }
    
}



