Dropped Water Bottle

Joe runs along two river banks with obstacles that force crossings; find the earliest time he intercepts a drifting bottle, or report impossibility.

Medium7Shortest pathGraphNo attempts yetTime limit2sMemory limit512 MB

Problem

Joe is on a multi-day tramping trip. While he is wading across a river, his empty water bottle falls out of his pack and drifts off downstream. He watches it for a while, decides it is worth chasing, returns to the left bank and puts his pack down. Making up his mind and getting back to the left bank takes 2 minutes, and the river flows at a steady 0.50.5 metres per second, so the bottle is already 6060 metres downstream when he starts to run.

Take the moment Joe starts running as time 00 and the point where the bottle fell as distance 00. At time tt seconds the bottle is at 60+0.5t60 + 0.5t metres.

On the left bank Joe runs at 22 metres per second. The right bank is rougher and he runs at 11 metre per second there. Both banks carry obstacles such as cliff faces that he cannot pass. When he meets one he has to cross to the opposite bank. He always crosses on a line perpendicular to the current, so a crossing carries him no distance downstream, and a crossing from one bank to the other takes 4040 seconds.

An obstacle given by dd and ll covers its own bank from dd to d+ld + l. Joe can stand at any point of his bank that is not strictly inside an obstacle, and the two end points dd and d+ld + l are usable. He runs only through such points, and he crosses the river only at a point that is usable on both banks. So if an obstacle on one bank ends exactly where an obstacle on the other bank begins, Joe crosses at that point. If one point lies strictly inside an obstacle on both banks at once, Joe cannot get past it.

To pick the bottle up, Joe wades from the point where he stands into the centre of the river. Reaching the centre takes 2020 seconds and carries him no distance downstream, so entering at point pp at time TT puts him in the centre of the river at pp at time T+20T + 20. If the bottle has already passed pp by then, he misses it. If it has not, he waits there and takes it the instant it reaches pp.

Compute the earliest time at which Joe picks up his water bottle.

Input

The input holds a single test case.

The first line has two integers nln_l and nrn_r, the number of obstacles on the left bank and on the right bank (0nl20000 \le n_l \le 2\,000, 0nr20000 \le n_r \le 2\,000).

Each of the next nln_l lines has two integers dd and ll describing a left-bank obstacle (0<d60000 < d \le 6\,000, 0<l60000 < l \le 6\,000). Here dd is the distance downstream from where the bottle was dropped to the start of the obstacle and ll is the length of the obstacle, both in metres.

The following nrn_r lines describe the right-bank obstacles in the same format.

On each bank the obstacles are given in increasing order of dd and do not overlap, though they may touch.

Output

Print the earliest time in seconds at which Joe picks up his bottle, rounded to exactly three digits after the decimal point. The exact value is always an integer multiple of 13\frac{1}{3} of a second, so the rounded value is unique. For an exact value of 662366\frac{2}{3} seconds, print 66.667.

If Joe cannot pick the bottle up, print IMPOSSIBLE.