시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 66 34 32 54.237%

문제

학교 대표팀은 1부터 번호가 매겨진 저지를 학생 선수들에게 배분하고자 한다. 저지의 사이즈는 S, M, L 중 하나이다 (물론 S=small, M=medium, L=Large다).

각각의 선수들은 구체적인 저지의 번호와 선호하는 사이즈를 요구했다. 선수들은 만약 자신이 원했던 번호가 아니거나, 선호하는 사이즈보다 작은 사이즈의 옷을 받으면 불만이 생길 것이다. 그들을 만족시키기 위해서는, 요구하는 번호가 맞고 사이즈는 같거나 그 이상이어야 한다. 두 명의 학생들이 같은 저지를 받을 수은 없다.

조건을 만족하는 최대 학생 수를 구하는 프로그램을 작성하여라.

입력

첫 번째 줄은 저지의 수인 J가 주어진다.

두 번째 줄은 선수들의 수인 A가 주어진다.

다음  J줄에는 등번호 j인 저지의 사이즈가 주어진다. (1 ≤ j ≤ J)

마지막 A줄에는 선수들이 요구하는 사이즈와 번호가 입력된다.

테스트케이스의 50%는 1 ≤ J ≤ 103 , 1 ≤ A ≤ 103 를 만족하고, 

나머지 50%는 1 ≤ J ≤ 106 , 1 ≤ A ≤ 106 를 만족한다.

출력

만족할 수 있는 최대의 선수의 수를 출력한다.

예제 입력 1

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

예제 출력 1

1

힌트

첫 번째 저지는 M이고, 3번째 선수가 L을 요구했기 때문에 첫 번째 저지는 주어질 수 없다. 두 번째 저지와 네 번째 저지는 요구된 적이 없고, 세 번째 저지는 S를 요구한 2번째 선수에게 주어진다.

W3sicHJvYmxlbV9pZCI6IjEwNzc0IiwicHJvYmxlbV9sYW5nIjoiMCIsInRpdGxlIjoiXHVjODAwXHVjOWMwIiwiZGVzY3JpcHRpb24iOiI8cD5cdWQ1NTlcdWFkNTAgXHViMzAwXHVkNDVjXHVkMzAwXHVjNzQwIDFcdWJkODBcdWQxMzAgXHViYzg4XHVkNjM4XHVhYzAwIFx1YjllNFx1YWNhOFx1YzljNCBcdWM4MDBcdWM5YzB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