Lefties vs. Righties
시간 제한1초메모리 제한1024 MB
모든 주제에 전문가를 최소 한 명씩 포함하면서 오른쪽 성향과 왼쪽 성향의 인터뷰 인원 수가 같아지도록 인터뷰할 전문가를 최소 인원으로 고른다.
문제
Election season has begun! The news network you work for wants to present expert opinions on a variety of important topics. To give the appearance of being unbiased, the news chief insists the experts that are interviewed cover a broad range of the political spectrum.
This seems difficult to do since the political spectrum is so varied, so you decide to go with the tried, tested, and true practice of calling each person either just a rightie or a leftie. Finally, you want to get this job done as quickly as possible meaning you want to conduct the fewest interviews possible.
More specifically, there are topics to be covered and experts. Each expert is experienced with only one of the topics you should cover, and each expert is also either a rightie or a leftie. Your job is to interview the fewest experts possible such that the following conditions hold.
-
For each topic, you interviewed at least one expert in that topic.
-
You interviewed each expert at most once (the audience would get bored otherwise).
-
The number of rightie experts you interviewed is the same as the number of leftie experts you interviewed.
입력
The first line of input contains two integers () and () denoting the number of topics and experts, respectively. Then lines follow, each containing an integer (), indicating the topic that the ’th expert is experienced with, and a single character (c\_ i \in \\{ R, L\\} ) indicating if the ’th expert is a rightie or a leftie.
출력
Output a single integer on a line by itself indicating the fewest interviews that can be conducted to satisfy these constraints. If it is not possible to satisfy all constraints, then simply ouput .