eolymp
bolt
Try our new interface for solving problems
Problems

Why Did the Cow Cross the Road (Silver)

Why Did the Cow Cross the Road (Silver)

Farmer John's cows are trying to learn to cross the road effectively. Remembering the old "why did the chicken cross the road?" joke, they figure the chickens must be experts on crossing the road, and go off in search of chickens to help them.

As it turns out, chickens are very busy creatures and have limited time to help the cows. There are c chickens on the farm, conveniently numbered 1 .. c, and each chicken i is only willing to help a cow at precisely time ti. The cows, never in a hurry, have more flexibility in their schedules. There are n cows on the farm, conveniently numbered 1 .. n, where cow j is able to cross the road between time Aj and time Bj. Figuring the "buddy system" is the best way to proceed, each cow j would ideally like to find a chicken i to help her cross the road; in order for their schedules to be compatible, i and j must satisfy AjtiBj.

If each cow can be paired with at most one chicken and each chicken with at most one cow, please help compute the maximum number of cow-chicken pairs that can be constructed.

Input

The first line contains c (1c20000) and n (1n20000). The next c lines contain t1 .. tc, and the next n lines contain Aj and Bj (AjBj) for j = 1 .. n. The A's, B's and t's are all non-negative integers (not necessarily distinct) of size at most 109.

Output

Please compute the maximum possible number of cow-chicken pairs.

Time limit 1 second
Memory limit 128 MiB
Input example #1
5 4
7
8
6
2
9
2 5
4 9
0 3
8 13
Output example #1
3
Source 2017 USACO February, Silver