World Wide Networks (WWN) operates large telecommunication networks and wants to build a new network in the country of Borduria that connects all n of its largest cities at the smallest possible total cost.
Several local companies already run small subnetworks, each of which interconnects some of the cities. To provide connectivity, WWN may use either of two mechanisms:
Every city has integer coordinates. There are q subnetworks, and q is always small (q≤8); the internal layout of a subnetwork is irrelevant, because buying it makes all of its cities mutually connected.
Choose which subnetworks to buy and which edges to build so that all n cities end up connected and the total cost — the prices of the bought subnetworks plus the cost of every built edge — is minimized.
The first line contains two integers n and q (1≤n≤1000, 0≤q≤8): the number of cities and the number of existing subnetworks. Cities are numbered from 1 to n.
Each of the next q lines describes one subnetwork. The line begins with an integer m, the number of cities in that subnetwork, then an integer w, its price (w≤2000000), then the m distinct city numbers belonging to it.
Each of the final n lines contains two integers xi and yi (0≤xi,yi≤3000): the coordinates of city i (city 1 on the first of these lines, city 2 on the second, and so on).
Print a single integer: the minimum total cost to connect all n cities.
The figures below are illustrations. The first two show a 115-city instance with 4 subnetworks and a solution that buys the first and third subnetworks (thick edges belong to a bought subnetwork; thin edges are built from scratch). The last two show the 7-city instance from the example and one of its optimal solutions, in which the first and second subnetworks are bought and the remaining connecting edges are built from scratch, for a total cost of 17.



