#P9811. [CCC 2015 S2] Jerseys

[CCC 2015 S2] Jerseys

Problem Description

There are jerseys numbered from 11 to nn that will be given to mm players. The jersey sizes, from small to large, are S, M, and L. Each player has a requirement for a jersey. Specifically, the ii-th player wants a jersey whose size is not smaller than aia_{i}, and the jersey number is bib_{i}.

Find the maximum number of players whose requirements can be satisfied.

Input Format

The first line contains an integer nn, and the second line contains an integer mm.

The next nn lines each contain a character cic_{i}, meaning the size of jersey number ii, where ci{S,M,L}c_{i} \in \{\text{S,M,L}\}.

The next mm lines each contain a character aja_{j} and an integer bjb_{j}, where aj{S,M,L}a_{j} \in \{\text{S,M,L}\}. The meaning is the same as in the description.

Output Format

Output one line with one integer, the maximum number of players whose requirements can be satisfied.

4
3
M
S
S
L
L 3
S 3
L 1
1

Hint

Constraints:

For 50%50\% of the testdata, 1n,m1031 \leq n,m \leq 10^{3}.

For 100%100\% of the testdata, 1n,m1061 \leq n,m \leq 10^{6}.

Translated by ChatGPT 5