You are given n points (x1,y1),…,(xn,yn) in the plane. Your goal is to navigate a robot from point (x1,y1) to point (xn,yn).
From its current point (xi,yi), the robot may travel to any other point (xj,yj) that is at most R units away, at a speed of 1 unit per second. Before it moves, however, the robot must turn until it faces (xj,yj); this turning happens at a rate of 1 degree per second.
Compute the shortest time needed for the robot to travel from point (x1,y1) to (xn,yn). Assume the robot initially faces (xn,yn).
To avoid floating-point precision issues, use the double data type rather than float. It is guaranteed that the unrounded shortest time is no more than 0.4 away from the nearest integer. If you use inverse trigonometric functions, prefer atan2() over acos() or asin().
The input contains multiple test cases. Each test case begins with a line containing two integers R and n: R is the maximum distance the robot may travel between points (10≤R≤1000), and n is the number of points (2≤n≤20).
Each of the next n lines contains two integers; the i-th of these lines contains xi and yi (−1000≤xi,yi≤1000). Every point is distinct.
The end of input is marked by a test case with R=n=−1.
For each test case, print a single line containing the shortest possible time in seconds (rounded to the nearest integer) required for the robot to travel from (x1,y1) to (xn,yn). If no such trip is possible, print impossible instead.