#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef complex<double> Point;
const double EPS = 1e-6;
int sign(double a){
    if(a > EPS) return 1;
    if(a < -EPS) return -1;
    return 0;
}
bool lt(double a, double b){
    return sign(a - b) < 0;
}
double dot(Point a, Point b){
    return real(conj(a) * b);
}
double cross(Point a, Point b){
    return imag(conj(a) * b);
}
int ccw(Point a, Point b, Point c){
    b -= a;
    c -= a;
    if(cross(b, c) > +EPS) return +1;
    if(cross(b, c) < -EPS) return -1;
    if(dot(b, c) < 0) return +2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}
struct Line : public vector<Point> {
    Line(const Point& a, const Point& b){
        push_back(a);
        push_back(b);
    }
    Point vector() const {
        return back() - front();
    }
};
bool paralell(Line l, Line m){
    return sign(cross(l.vector(), m.vector())) == 0;
}
Point crosspointLL(Line l, Line m){
    double A = cross(l.vector(), m.vector());
    double B = cross(l.vector(), l[1] - m[0]);
    if(sign(A) == 0) assert(false);
    return m[0] + m.vector() * B / A;
}
struct Circle {
    Point p;
    double r;
    Circle() {}
    Circle(Point p_, double r_) : p(p_), r(r_) {}
};
vector<Line> tangents_through_point(const Circle& C, const Point& p){
    vector<Line> tangents;
    double d = abs(C.p - p);
    // d ^ 2 == r ^ 2 + e ^ 2
    double e = sqrt(d * d - C.r * C.r); // 点pと円の接点の距離
    // d * sin(th) = r
    double th = asin(C.r / d);
    Point q1 = p + (C.p - p) * polar(1.0, +th) * e / d;
    Point q2 = p + (C.p - p) * polar(1.0, -th) * e / d;
    tangents.push_back(Line(p, q1));
    tangents.push_back(Line(p, q2));
    return tangents;
}
bool intersectSP(Line s, Point p) {
    return ccw(s[0], s[1], p) == 0;
}
Point projection(Line l, Point p){
    double t = dot(p - l[0], l.vector()) / norm(l.vector());
    return l[0] + t * l.vector();
}
double distanceSP(Line s, Point p){
    Point r = projection(s, p);
    if(intersectSP(s, r)) return abs(r - p); // 垂線が線分に交わるとき
    return min(abs(s[0] - p), abs(s[1] - p));
}
enum{ OUT, ON, IN };
int contains(const Circle& C, const Point& p){
    double d = abs(C.p - p);
    if(sign(d - C.r) > 0) return OUT;
    if(sign(d - C.r) == 0) return ON;
    return IN;
}
bool intersectCS(const Circle& C, const Line& l){
    int c1 = contains(C, l[0]);
    int c2 = contains(C, l[1]);
    if(c1 > c2) swap(c1, c2);

    if(c1 == OUT && c2 == IN) return true;
    if(c1 == IN  && c2 == IN) return false;
    if(c1 == ON) return false;
    double d = distanceSP(l, C.p);
    if(sign(d - C.r) < 0) return true;
    if(sign(d - C.r) == 0) return false;
    if(sign(d - C.r) > 0) return false;
}
void print(Line l){
    cout << l[0] << " -> " << l[1] << endl;
}

int main(){
    const double W = 50;
    const double H = 94;
    int N, D;
    cin >> N >> D;
    vector<Circle> c(N);
    REP(i, N){
        double x, y, r;
        cin >> x >> y >> r;
        c[i] = Circle(Point(x, y), r);
    }
    const Point start(W / 2, 0);
    const Point goal (W / 2, H);
    vector<Line> st, gt;
    for(int i = 0; i < N; i++){
        vector<Line> sv = tangents_through_point(c[i], start);
        vector<Line> gv = tangents_through_point(c[i], goal );
        st.insert(st.end(), sv.begin(), sv.end());
        gt.insert(gt.end(), gv.begin(), gv.end());
    }
    const double INF = 1e9;
    double ans = INF;

    Line shortest(start, goal);
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(intersectCS(c[i], shortest)) cnt++;
    }
    if(cnt <= D){
        ans = abs(shortest.vector());
    }

    for(Line sl : st){
        for(Line gl : gt){
            if(paralell(sl, gl)) continue;
            Point cp = crosspointLL(sl, gl);
            if(!(lt(0, cp.real()) && lt(cp.real(), W))) continue;
            if(!(lt(0, cp.imag()) && lt(cp.imag(), H))) continue;
            Line sm(start, cp);
            Line gm(cp, goal);
            int cnt = 0;
            for(int i = 0; i < N; i++){
                if(intersectCS(c[i], sm)) cnt++;
                if(intersectCS(c[i], gm)) cnt++;
                if(contains(c[i], cp) == IN) cnt--;
            }
            if(cnt <= D){
                double d = abs(sm.vector()) + abs(gm.vector());
                ans = min(ans, d);
            }
        }
    }
    if(ans == INF) {
        printf("-1\n");
    } else {
        printf("%.12f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1300