Camera Crew
YOU: "So you were the official camera guy elected to film the event. Did you film anything else while setting up?"
JOSH: "Oh, yeah, actually! So, I had this idea to do like, a behind-the-scenes thing? Just showing how much work goes into setting everything up, you know, for our social media. I thought that would be really cool."
YOU: "Any footage from around the time of the incident?"
JOSH: "Um, yeah, actually. Ritisha had just finished putting up all the posters, so I asked if I could interview her real quick, just like, get her thoughts on the night. She seemed a little sad, but like, excited too? For how it was all gonna go."
YOU: "Anything on the audio?"
JOSH: "There's a thud. Kind of far off, maybe two minutes in? I didn't think anything of it, figured it was more setup. I feel really bad now. You can watch the tape. I really hope it helps."
Josh has been assigned to ensure that important moments throughout the night are filmed for social media. However, he doesn't want to run around himself, so he wants to hire some photographers to help. These photographers are expensive, so Josh wants to minimise the number he needs.
There are scheduled moments throughout the night, and
important guests that Josh wants coverage of. Each scheduled moment will be attended by some subset of the
guests. A photographer can cover at most one guest at any given moment.
For each guest, Josh wants one photographer assigned to cover them from the first moment they appear until the last moment they appear. During this entire period, that photographer cannot be reassigned, even at moments where the guest is not present, since Josh wants each guest's footage to be contained in a single video file, and he cannot afford editing software.
After the final moment containing a photographer's current guest has passed, that photographer can switch to filming a new guest in the next scheduled moment, as long as that guest has not already made their first appearance. Josh has already received the full schedule of events. What is the minimum number of photographers he must hire to have perfect coverage?
Input
The first line contains two integers and
(
), the number of key moments and the number of important guests. Each guest is labelled
through
.
The next lines describe the scheduled moments. The
th of these lines starts with an integer
(
), the number of guests present at the
th moment, followed by
integers
(
), the labels of those guests.
A guest can appear at most once in a single moment, and each guest is guaranteed to appear in at least one scheduled moment.
The sum of all over the input is at most
.
Output
Output a single integer - the minimum number of photographers that Josh must hire to cover all important guests through all moments they appear in.
Example
Input 1
3 2
1 1
2 1 2
1 2
Output 1
2
Here there are three moments and two key guests. We cannot have a single photographer cover both guests, as they are both present at the second moment. Thus, Josh needs to hire two photographers.
Input 2
3 3
1 1
1 2
1 3
Output 2
1
Although there are three important guests, their required coverage periods do not overlap, so it is possible for a single photographer to cover all of them.
Input 3
7 6
2 1 2
2 2 3
3 1 3 4
2 4 5
2 2 5
1 6
2 3 6
Output 3
4
Comments