Buy or Build

No attempts yetTime limit1sMemory limit128 MB

Problem

World Wide Networks (WWN) operates large telecommunication networks and wants to build a new network in the country of Borduria that connects all nn 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:

  • Build an edge directly between two cities. Its cost is exactly the square of the Euclidean distance between them: for cities at (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) the cost is (x1x2)2+(y1y2)2(x_1 - x_2)^2 + (y_1 - y_2)^2.
  • Buy a subnetwork. Buying subnetwork cc costs wcw_c and immediately connects all cities that belong to it. A subnetwork must be bought as a whole and cannot be split.

Every city has integer coordinates. There are qq subnetworks, and qq is always small (q8q \le 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 nn cities end up connected and the total cost — the prices of the bought subnetworks plus the cost of every built edge — is minimized.

Input

The first line contains two integers nn and qq (1n10001 \le n \le 1000, 0q80 \le q \le 8): the number of cities and the number of existing subnetworks. Cities are numbered from 11 to nn.

Each of the next qq lines describes one subnetwork. The line begins with an integer mm, the number of cities in that subnetwork, then an integer ww, its price (w2000000w \le 2\,000\,000), then the mm distinct city numbers belonging to it.

Each of the final nn lines contains two integers xix_i and yiy_i (0xi,yi30000 \le x_i, y_i \le 3000): the coordinates of city ii (city 11 on the first of these lines, city 22 on the second, and so on).

Output

Print a single integer: the minimum total cost to connect all nn cities.

Notes

The figures below are illustrations. The first two show a 115115-city instance with 44 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 77-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 1717.