cho.sh
Notes
Loading...

Stepping-Stone Race 2

Time limit

2s

Memory limit

128 MB

Problem

Stepping stones were originally built simply to cross a stream. People who enjoy games, however, decided to hold a race by jumping across them.

Each stepping stone is represented by a coordinate pair (x, y). The starting point is always the origin (0, 0). During the race, you may jump only to a stepping stone whose x-coordinate differs from your current stone by at most 2 and whose y-coordinate also differs by at most 2. The finish line is a line parallel to the x-axis. When you reach any stepping stone whose y-coordinate is the same as the finish line's y-coordinate, you have crossed the finish line and the race ends.

Given the positions of the stepping stones, find the fastest route to finish the race. A fastest route is a route whose total jump length is as small as possible. A jump from (x1, y1) to (x2, y2) has length sqrt((x1 - x2)^2 + (y1 - y2)^2).

Input

The first line contains the number of stepping stones N and the y-coordinate F of the finish line.

Each of the next N lines contains the coordinates of one stepping stone.

N is a positive integer no greater than 50,000. F and every coordinate are integers between 0 and 1,000,000, inclusive. No input stone has a y-coordinate greater than F. The origin (0, 0) is not included among the N stepping stones, but it is still the starting point.

Output

Print one integer: the length of the fastest route, rounded to the nearest integer. If reaching the finish line is impossible, print -1.

Hint

Following the route (0,0) - (1,2) - (3,2) - (4,1) - (6,3) gives a total length of 8.4787..., and this is the shortest route.