ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2204. Friends and Exams

Time limit: 1.0 second
Memory limit: 256 MB
In the multiverse, there is another version of Yekaterinburg and UrFU, where the exam session is just starting. Their exams are entire hackathons that last for several consecutive days without breaks. This semester, the students have n exams. Additionally, the student has a choice: to take the i-th exam either from fli to fri days or from sli to sri days. It is clear that sli > fri, as the teachers also need to rest. The people in parallel Yekaterinburg are very orderly, so their exams are conducted in sequence, meaning: sri < fli+1.
The exam session is one thing, but student Semyon has many planned trips with friends, specifically m of them. Trip number i takes place from li to ri days inclusive. Since the group of friends is the same, the trips do not overlap in days.
Naturally, Semyon will not miss any exam; otherwise, he will be expelled. This means that during the chosen intervals for the exams, he cannot rest with friends. However, he can choose one of the two options for the exam and go on vacation during the other. Thus, he wondered how many times he can maximally go on vacation with friends while optimally choosing the dates for taking all the exams.

Input

The first line contains two integers n and m — the number of exams and the number of planned trips with friends (1 ≤ n, m ≤ 105).
The following n lines contain four integers fli, fri, sli, and sri separated by spaces — two intervals during which Semyon can take the i-th exam (1 ≤ flifri < slisri ≤ 109, sri < fli+1 for in − 1).
The next m lines contain two integers li and ri separated by spaces — the days planned for the i-th trip with friends (1 ≤ liri ≤ 109, ri < li+1 for im − 1).

Output

Output a single integer — the maximum number of times Semyon can go on vacation with friends while optimally choosing the dates for taking all exams.

Sample

inputoutput
3 5
3 5 7 9
43 50 51 58
100 103 111 114
6 6
47 47
101 101
103 103
112 112
4
Problem Author: Ivan Kogut
Problem Source: University academic school olympiad in informatics 2022