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.
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 (1≤j≤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 1≤J≤103 and 1≤A≤103, and the other half satisfy 1≤J≤106 and 1≤A≤106.
Print the largest number of players that can be satisfied.
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.