John has a graph with n vertices labeled with integers 1,…,n. Initially, there are no edges in the graph. Then John modifies the graph k times, each time adding a clique to the graph. He chooses an integer a and a set S which is a non-empty subset of the set of integers 1,2,…,n. For each unordered pair (i,j) such that i,j∈S and i=j, John adds an undirected edge between the vertices i and j with weight a. It is possible that parallel edges appear in John's graph.
The distance between vertices u and v is defined as follows. Denote d_u,v as the minimum weight of the edge between vertices u and v, or ∞ if there is no such edge. Then dist(u,v)=min_i_1,…,i_p(d_u,i_1+d_i_1,i_2+…+d_i_p−1,i_p+d_i_p,v). In other words, the distance is the length of the shortest path between u and v.
Your task is to calculate ∑_i=1n−1∑_j=i+1ndist(i,j). It is guaranteed that all summands are finite.
The first line contains two integers n and k (1≤n≤100,000, 1≤k≤18). The next k lines contain the descriptions of the added cliques. Each of these lines contains integers a (1≤a≤107), ∣S∣ (1≤∣S∣≤n), and then ∣S∣ integers s_1,…,s_∣S∣ (1≤s_i≤n, all s_i are distinct). These are the weight of edges in the clique, the number of vertices in the clique, and the labels of these vertices, respectively.
The sum of all ∣S∣ in the input does not exceed 300,000.
Output a single integer: the answer to the problem.