Toll

No attempts yetTime limit2sMemory limit256 MB

Problem

Robbery on the Silk Road has grown, and fewer and fewer merchants travel along it. A robber posted anywhere on the route demands as much money as he can from every merchant who passes. Merchants now prefer other routes even when that makes their journey longer, so the robbers' income has fallen. Moradbeig, the chief of the robbers, has replaced the old practice with a toll system.

Under this system each robber is confined to one square area, boundary included, called his territory. Territories are not assumed to be disjoint. The toll inside any territory is exactly 1 Oshloob. The remaining rules are these.

  1. A robber cannot collect the toll outside his own territory.
  2. A robber who receives the toll must issue a passing ticket that is specific to his territory. With that ticket the merchant may move freely inside the territory without paying any other robber. Once the merchant leaves the territory the ticket becomes invalid at once and cannot be used again.
  3. Without a valid ticket a merchant cannot pass through a robber's territory.
  4. If the merchant likes, he may void his current ticket himself and take a new ticket from any robber whose territory contains his position.

Marco Polo, a wealthy merchant, plans to travel the Silk Road from its beginning to its end. The situation is better than it was, and he still wants to pay less toll. Write a program that computes the minimum toll Marco Polo has to pay to traverse the whole route. The Silk Road is a rectilinear path, so every segment of it is either horizontal or vertical.

Input

The input holds several test cases. Each test case starts with a line containing two positive integers nn and mm (n,m1000n, m \le 1000), the number of territories and the number of vertices of the Silk Road. The next nn lines describe the territories, one per line. Each of those lines contains non-negative integers xx, yy and kk (x,y106x, y \le 10^6, k1000k \le 1000), where (x,y)(x, y) is the lowest and leftmost corner of the territory and kk is its side length. Each of the next mm lines gives the coordinates of a vertex of the Silk Road, in the order the vertices appear along the route. The route does not intersect itself. The input ends with a line containing 0 0, which is not processed.

Output

For each test case, print one line with the minimum toll Marco Polo must pay.