Cactus#5351

Cactus

1 second
128 megabytes
Easy

Cactus is a connected undirected graph in which every edge lies on at most one simple cycle. Intuitively cactus is a generalization of a tree where some cycles are allowed. Your task first is to verify if the given graph is a cactus or not. Important difference between a cactus and a tree is that a cactus can have a number of spanning subgraphs that are also cactuses. The number of such subgraphs (including the graph itself) determines cactusness of a graph (this number is one for a cactus that is just a tree). The cactusness of a graph that is not a cactus is considered to be zero.

prb5351

The first graph on the picture is a cactus with cactusness . The second graph is not a cactus because edge lies on two cycles. The third graph is not a cactus because it is not connected.

Input

The first line contains two integer numbers and (1 \leq n \leq 20000, 0 \leq m \leq 1000). Here is the number of vertices in the graph. Vertices are numbered from to . Edges of the graph are represented by a set of edge-distinct paths, where is the number of such paths.

Each of the following lines contains a path in the graph. A path starts with an integer number k_i (2 \leq k_i \leq 1000) followed by k_i integers from to . These k_i integers represent vertices of a path. Path can go to the same vertex multiple times, but every edge is traversed exactly once in the whole input data. There are no multiedges in the graph (there is at most one edge between any two vertices).

Output

Write a single integer number - the cactusness of the given graph. Note that cactusness can be quite a large number.

Examples

Example 1

Loading
Loading