#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5;
const int MAX_D = 5;
const double H = 94;
const double W = 50;
const double sx = 25, sy = 0, gx = 25, gy = 94;
const double PI = acos(-1.0);
const double STX = PI / 2, GTX = -PI / 2;
const double DINF = 1e60;
template <typename T>
struct Pt {
  T x, y;
  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt &pt) : x(pt.x), y(pt.y) {}
  bool operator==(const Pt pt) const { return x == pt.x && y == pt.y; }
  Pt<T> operator+(const Pt pt) const { return Pt<T>(x + pt.x, y + pt.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt pt) const { return Pt<T>(x - pt.x, y - pt.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt v) const { return x * v.x + y * v.y; }
  T cross(Pt v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt pt) { return Pt<T>((x + pt.x) / 2, (y + pt.y) / 2); }
  T d2() { return x * x + y * y; }
  double d() { return sqrt(d2()); }
  Pt<T> rot(double th) {
    double c = cos(th), s = sin(th);
    return Pt<T>(c * x - s * y, s * x + c * y);
  }
  Pt<T> rot90() { return Pt<T>(-y, x); }
  bool operator<(const Pt &pt) const {
    return x < pt.x || (x == pt.x && y < pt.y);
  }
  void print(string format) {
    printf(("(" + format + ", " + format + ")\n").c_str(), x, y);
  }
  void print() { print("%.6lf"); }
};
struct CL {
  Pt<double> p;
  double t0, t1;
  CL() {}
  CL(const Pt<double> &_p, double _t0, double _t1) : p(_p), t0(_t0), t1(_t1) {}
};
Pt<double> cs[MAX_N];
double rs[MAX_N];
bool cross_lines(const Pt<double> &ap, const Pt<double> av,
                 const Pt<double> &bp, const Pt<double> bv, CL &cl) {
  double op01 = av.cross(bv);
  if (op01 == 0.0) {
    Pt<double> v = bp - ap;
    if (v.cross(av) != 0.0) return false;
    Pt<double> a1 = ap + av;
    Pt<double> b1 = bp + bv;
    return ((bp - ap).dot(b1 - ap) <= 0.0 || (bp - a1).dot(b1 - a1) <= 0.0 ||
            (ap - bp).dot(a1 - bp) <= 0.0 || (ap - b1).dot(a1 - b1) <= 0.0);
  }
  Pt<double> v = bp - ap;
  double op0 = v.cross(av);
  double op1 = v.cross(bv);
  double t0 = op1 / op01;
  double t1 = op0 / op01;
  cl.p = bv * t1 + bp;
  cl.t0 = t0;
  cl.t1 = t1;
  return true;
}
void get_range(Pt<double> &p0, Pt<double> &c, double r, double &minth,
               double &maxth) {
  Pt<double> v(c - p0);
  double th0 = atan2(v.y, v.x);
  double l = sqrt(v.d2() - r * r);
  double dth = atan2(r, l);
  minth = th0 - dth;
  maxth = th0 + dth;
}
void merge_range(vector<pair<double, double> > &rs, double minth,
                 double maxth) {
  vector<pair<double, double> > rs0;
  for (vector<pair<double, double> >::iterator vit = rs.begin();
       vit != rs.end(); vit++) {
    double &r0 = vit->first, &r1 = vit->second;
    if (r1 <= minth || maxth <= r0)
      rs0.push_back(*vit);
    else {
      if (r0 <= minth && minth <= r1)
        rs0.push_back(pair<double, double>(r0, minth));
      if (r0 <= maxth && maxth <= r1)
        rs0.push_back(pair<double, double>(maxth, r1));
    }
  }
  rs = rs0;
}
void min_th(vector<pair<double, double> > &rs, double thx, double &min0,
            double &min1) {
  for (vector<pair<double, double> >::iterator vit = rs.begin();
       vit != rs.end(); vit++) {
    double &r0 = vit->first, &r1 = vit->second;
    if (r0 <= thx && thx <= r1) {
      min0 = min1 = thx;
      return;
    }
    if (r1 <= thx && min0 < r1) min0 = r1;
    if (r0 >= thx && min1 > r0) min1 = r0;
  }
}
void print_range(vector<pair<double, double> > &rs) {
  for (vector<pair<double, double> >::iterator vit = rs.begin();
       vit != rs.end(); vit++)
    printf("(%lf,%lf) ", vit->first, vit->second);
  putchar('\n');
}
int main() {
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < n; i++) cin >> cs[i].x >> cs[i].y >> rs[i];
  int nbits = 1 << n;
  Pt<double> sp(sx, sy), gp(gx, gy);
  double sth0 = 0.0, sth1 = PI, gth0 = -PI, gth1 = 0.0;
  for (int bits = 0; bits < nbits; bits++) {
    int bn = 0;
    for (int i = 0; i < n; i++)
      if (bits & (1 << i)) bn++;
    if (bn > d) continue;
    vector<pair<double, double> > srs, grs;
    srs.push_back(pair<double, double>(0.0, PI));
    grs.push_back(pair<double, double>(-PI, 0.0));
    for (int i = 0; i < n; i++) {
      if (bits & (1 << i)) continue;
      double st0, st1, gt0, gt1;
      get_range(sp, cs[i], rs[i], st0, st1);
      get_range(gp, cs[i], rs[i], gt0, gt1);
      merge_range(srs, st0, st1);
      merge_range(grs, gt0, gt1);
    }
    min_th(srs, STX, sth0, sth1);
    min_th(grs, GTX, gth0, gth1);
  }
  CL cl0, cl1;
  Pt<double> sv0(cos(sth0), sin(sth0)), sv1(cos(sth1), sin(sth1));
  Pt<double> gv0(cos(gth0), sin(gth0)), gv1(cos(gth1), sin(gth1));
  cross_lines(sp, sv0, gp, gv1, cl0);
  cross_lines(sp, sv1, gp, gv0, cl1);
  double mind = DINF;
  double d0 = (cl0.p - sp).d() + (cl0.p - gp).d();
  double d1 = (cl1.p - sp).d() + (cl1.p - gp).d();
  if (cl0.p.x > 0.0 && cl0.p.x < W && mind > d0) mind = d0;
  if (cl1.p.x > 0.0 && cl1.p.x < W && mind > d1) mind = d1;
  if (mind >= DINF)
    puts("-1");
  else
    printf("%.10lf\n", mind);
  return 0;
}
