Camera Crew


Submit solution

Points: 1
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python, Rust

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 n scheduled moments throughout the night, and m important guests that Josh wants coverage of. Each scheduled moment will be attended by some subset of the m 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 n and m (1 \leq n,m \leq 10^5), the number of key moments and the number of important guests. Each guest is labelled 1 through m.

The next n lines describe the scheduled moments. The ith of these lines starts with an integer k_i (1 \leq k_i \leq m), the number of guests present at the ith moment, followed by k_i integers p_1, \dots, p_{k_i} (1 \leq p_j \leq m), 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 k_i over the input is at most 10^5.

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

There are no comments at the moment.