#K83362. Minimize Bus Stops

    ID: 36181 Type: Default 1000ms 256MiB

Minimize Bus Stops

Minimize Bus Stops

You are given the number of bus routes and the maximum stop number. Each bus route is represented by a list of stops. Your task is to compute the minimal number of stops required if you consider all the distinct stops available in all bus routes.

In other words, you need to determine the number of unique stops covered by all buses. This is equivalent to finding the cardinality of the union of all bus route stops.

The formula behind the challenge can be expressed in \(\LaTeX\) as follows:

\[ \text{result} = \left| \bigcup_{i=1}^{B} \text{route}_i \right| \]

inputFormat

The first line contains two integers \(B\) and \(S\) separated by a space, where \(B\) is the number of bus routes, and \(S\) is the maximum possible stop number. The next \(B\) lines each contain a bus route. Each route is given as a sequence of one or more integers (each integer representing a bus stop) separated by spaces.

Note: The input should be read from standard input (stdin).

outputFormat

Output a single integer — the number of unique stops, which is the minimal number of stops after optimizing all the bus routes.

Note: The output should be printed to standard output (stdout).

## sample
2 5
1 2 3 4 5
1 3 5 2 4
5