Jerseys

No attempts yetTime limit1sMemory limit256 MB

Problem

The school team wants to hand out jerseys numbered 1 to J to its players. Every jersey has size S, M, or L.

Each player named one jersey number and a preferred size. A player becomes unhappy after receiving a jersey with a different number, or a jersey smaller than the preferred size. To satisfy a player, the jersey number must equal the requested number and the jersey size must be equal to or larger than the preferred size. The sizes grow in the order S, M, L. Two players cannot share one jersey.

Write a program that finds the largest number of players that can be satisfied.

Input

The first line contains J, the number of jerseys.

The second line contains A, the number of players.

Each of the next J lines contains the size of the jersey numbered j, one per line (1jJ1 \le j \le J).

Each of the last A lines contains the size a player prefers and the jersey number that player requests, separated by one space. The jersey number is between 1 and J.

Half of the test cases satisfy 1J1031 \le J \le 10^3 and 1A1031 \le A \le 10^3, and the other half satisfy 1J1061 \le J \le 10^6 and 1A1061 \le A \le 10^6.

Output

Print the largest number of players that can be satisfied.

Note

In the sample, jersey 1 has size M while the player who requested number 1 prefers L, so that jersey goes to nobody. Jerseys 2 and 4 were never requested. Jersey 3 goes to the player who requested number 3 and prefers size S.