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.InputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main{
    public static void main(String[] args) throws IOException {
        Scanner scanner=new Scanner(System.in);
        PrintWriter out= new PrintWriter(System.out);
        //==================================================//
        //answer here:
        int p=scanner.nextInt();
        int q=scanner.nextInt();
        int l=scanner.nextInt();
        int r=scanner.nextInt();
        boolean[] isUnique=new boolean[r-l+1];
        pair[] littlez=new pair[p];
        pair[] littlex=new pair[q];
        for (int i=0; i<p; i++){
           littlez[i]=new pair(scanner.nextInt(),scanner.nextInt());
        }
        for (int i=0; i<q; i++){
            littlex[i]=new pair(scanner.nextInt(),scanner.nextInt());
        }
        int count=0;
        for (int i=l; i<=r; i++){
            for (pair z:littlez){
                for (pair x:littlex){
                    if (x.end+i<z.start || x.start+i>z.end){
                            continue;
                        }else if (!isUnique[i-l]){
                            isUnique[i-l]=true;
                            count++;
                       }
                }
            }
        }
        out.println(count);
        //==================================================//
        out.close();
    }
}

class Scanner {
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}
}
class pair{
    int start;
    int end;
    public pair(int start, int end){
        this.start=start;
        this.end=end;
    }
    public String toString(){
        return this.start+" "+this.end;
    }
}