P9811 [CCC 2015 S2] Jerseys

Description

There are jerseys numbered from $1$ to $n$ that will be given to $m$ players. The jersey sizes, from small to large, are S, M, and L. Each player has a requirement for a jersey. Specifically, the $i$-th player wants a jersey whose size is **not smaller than** $a_{i}$, and the jersey number is $b_{i}$. Find the maximum number of players whose requirements can be satisfied.

Input Format

The first line contains an integer $n$, and the second line contains an integer $m$. The next $n$ lines each contain a character $c_{i}$, meaning the size of jersey number $i$, where $c_{i} \in \{\text{S,M,L}\}$. The next $m$ lines each contain a character $a_{j}$ and an integer $b_{j}$, where $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.

Explanation/Hint

**Constraints:** For $50\%$ of the testdata, $1 \leq n,m \leq 10^{3}$. For $100\%$ of the testdata, $1 \leq n,m \leq 10^{6}$. Translated by ChatGPT 5