#include #include #include using namespace std; typedef vector VF; typedef vector VVF; typedef vector VVF; typedef vector VI; const double PI = 3.141592653589793238462643383279502884197169399; // return squared distance between points i and j int sqdist (const VI &x, const VI &y, int i, int j){ int dx = x[i]-x[j]; int dy = y[i]-y[j]; return dx*dx + dy*dy; } // return angle between i1 --> j1 and i1 --> j2 vectors in degrees double turningtime (const VI &x, const VI &y, int i1, int j1, int i2, int j2){ double ang1 = atan2 (y[j1]-y[i1], x[j1]-x[i1]); double ang2 = atan2 (y[j2]-y[i2], x[j2]-x[i2]); double ang = min (fabs(ang1-ang2), 2*PI-fabs(ang1-ang2)); return ang * (180/PI); } int main(){ while (true){ // read input int R, n; cin >> R >> n; if (R == -1 && n == -1) break; VI x(n+1), y(n+1); for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; // weights[i*(n+1)+j][j*(n+1)+k] = cost of going from j->k if we just went from i->j VVF weights ((n+1)*(n+1), VF ((n+1)*(n+1), 1e20)); for (int i = 2; i <= n; i++) if (sqdist(x,y,1,i) <= R*R) weights[0*(n+1)+1][1*(n+1)+i] = sqrt(sqdist(x,y,1,i)) + turningtime (x,y,1,n,1,i); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (j != i && sqdist(x,y,i,j) <= R*R) for (int k = 1; k <= n; k++) if (k != i && k != j && sqdist(x,y,j,k) <= R*R) weights[i*(n+1)+j][j*(n+1)+k] = sqrt(sqdist(x,y,j,k)) + turningtime (x,y,i,j,j,k); // run Dijkstra VF d((n+1)*(n+1), 1e20); VI done ((n+1)*(n+1)); int here = 0*(n+1)+1; d[here] = 0; while (here != -1){ done[here] = 1; int best = -1; for (int i = 0; i < (n+1)*(n+1); i++) if (!done[i]){ if (d[i] > d[here] + weights[here][i]) d[i] = d[here] + weights[here][i]; if (best == -1 || d[i] < d[best]) best = i; } here = best; } // find best path double best_path = 1e20; for (int i = 1; i <= n; i++){ if (d[i*(n+1)+n] < best_path) best_path = d[i*(n+1)+n]; } if (best_path > 1e15) cout << "impossible" << endl; else cout << (int)(best_path + 0.5) << endl; } }