#include <bits/stdc++.h>
using namespace std;
static const double pi = acos(-1.0);
double dot(complex<double> a, complex<double> b) {
  return a.real() * b.real() + a.imag() * b.imag();
}
double cross(complex<double> a, complex<double> b) {
  return a.real() * b.imag() - a.imag() * b.real();
}
int ccw(complex<double> a, complex<double> b, complex<double> c) {
  if (cross(b - a, c - a) > 1e-10) return 1;
  if (cross(b - a, c - a) < -1e-10) return -1;
  if (dot(b - a, c - a) < -1e-10) return 2;
  if (norm(b - a) + 1e-10 < norm(c - a)) return -2;
  return 0;
}
bool is_cross(pair<complex<double>, complex<double> > a,
              pair<complex<double>, complex<double> > b) {
  if (ccw(a.first, a.second, b.first) * ccw(a.first, a.second, b.second) <= 0 &&
      ccw(b.first, b.second, a.first) * ccw(b.first, b.second, a.second) <= 0)
    return true;
  return false;
}
double p_to_s_dist(complex<double> p,
                   pair<complex<double>, complex<double> > s) {
  if (dot(p - s.first, s.second - s.first) >= 0 &&
      dot(p - s.second, s.first - s.second) >= 0)
    return abs(cross(p - s.first, s.second - s.first)) /
           abs(s.second - s.first);
  return min(abs(p - s.first), abs(p - s.second));
}
double s_to_s_dist(pair<complex<double>, complex<double> > a,
                   pair<complex<double>, complex<double> > b) {
  if (is_cross(a, b)) return 0;
  return min(min(p_to_s_dist(a.first, b), p_to_s_dist(a.second, b)),
             min(p_to_s_dist(b.first, a), p_to_s_dist(b.second, a)));
}
double Poly_to_Poly_dist(vector<complex<double> > a,
                         vector<complex<double> > b) {
  double dist = 1e8;
  int na = a.size(), nb = b.size();
  a.push_back(a[0]);
  b.push_back(b[0]);
  for (int i = 0; i < na; ++i) {
    for (int j = 0; j < na; ++j) {
      dist = min(
          dist,
          s_to_s_dist(pair<complex<double>, complex<double> >(a[i], a[i + 1]),
                      pair<complex<double>, complex<double> >(b[j], b[j + 1])));
    }
  }
  return dist;
}
vector<complex<double> > star(complex<double> p, double r, double a) {
  vector<complex<double> > ret;
  for (int i = 0; i < 5; ++i) {
    ret.push_back(
        complex<double>(polar(r, (a + 90 + 144 * i) / 360 * 2 * pi) + p));
  }
  return ret;
}
int main() {
  int N, M, pair<complex<double>, complex<double> >;
  double x, y, a, r;
  while (cin >> N >> M >> pair<complex<double>, complex<double> >, N) {
    vector<vector<complex<double> > > stars(N);
    for (int i = 0; i < N; ++i) {
      cin >> x >> y >> a >> r;
      stars[i] = star(complex<double>(x, y), r, a);
    }
    vector<vector<double> > WF(N, vector<double>(N, 1e8));
    for (int i = 0; i < N; ++i) {
      for (int j = i; j < N; ++j) {
        if (i == j)
          WF[i][j] = 0;
        else {
          WF[i][j] = Poly_to_Poly_dist(stars[i], stars[j]);
          WF[j][i] = WF[i][j];
        }
      }
    }
    for (int k = 0; k < N; ++k) {
      for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
          WF[i][j] = min(WF[i][j], WF[i][k] + WF[k][j]);
        }
      }
    }
    printf("%.10lf\n", WF[M - 1][pair<complex<double>, complex<double> > - 1]);
  }
  return 0;
}
