object Main extends App {
  import scala.collection.mutable
  import scala.io.StdIn._


  val tolerance = 0.0000001
  val Array(n, d) = readLine.trim.split(' ').map(_.toInt)
  val circles = Array.tabulate(n){_ ⇒
    val Array(x, y, r) = readLine.trim.split(' ').map(_.toInt)
    Circle(Point(x, y), r)
  }
  val start = Point(25, 0)
  val goal = Point(25, 94)
  val stage = Square(0, 50, 0, 94)
  if (countIntersections(start, start, goal, circles) <= d){
    println(start.distanceFrom(goal))
  }else {
    val lineS = circles.flatMap(c ⇒ c.tangentsFrom(start))
    val lineG = circles.flatMap(c ⇒ c.tangentsFrom(goal))
    val distances = for {a ← lineS
      b ← lineG
      mid ← a.crossPoint(b).filter(stage.contains)
      if countIntersections(start, mid, goal, circles) <= d
    } yield {
      start.distanceFrom(mid) + mid.distanceFrom(goal)
    }
    println(if (distances.isEmpty) -1 else distances.min)
  }

  case class Square(left: Int, right: Int, top: Int, bottom: Int) {
    def contains(point: Point): Boolean = left - tolerance < point.x && point.x < right + tolerance && top - tolerance < point.y && point.y < bottom + tolerance
  }
  def countIntersections(from: Point, mid: Point, to: Point, circles: Array[Circle]): Int = {
    val edgeA = Edge(from, mid)
    val edgeB = Edge(mid, to)
    circles.count(c ⇒ c.hasIntersection(edgeA)) + circles.count(c ⇒ c.hasIntersection(edgeB)) - (if (circles.exists(c ⇒ c.contains(mid))) 1 else 0)
  }
  case class Circle(center: Point, radius: Double) {
    def contains(point: Point): Boolean = center.distanceFrom(point) < radius + tolerance
    def tangentsFrom(point: Point): List[Line] = {
      val sin = radius / center.distanceFrom(point)
      val diff = Angle(Point(math.sqrt(1 - sin * sin), sin))
      val angle = Angle(Point(center.x - point.x, center.y - point.y))
      List(Line(point, angle + diff), Line(point, angle - diff))
    }
    def hasIntersection(edge: Edge): Boolean = {
      if (contains(edge.from) || contains(edge.to)) true
      else {
        val asLine = Line(edge.from, edge.to)
        if (asLine.distanceFrom(center) < radius - tolerance) {
          asLine.crossPoint(Line(center, Angle(asLine).rotate90)).exists(edge.onEdge)
        } else {
          false
        }
      }
    }
    //def crossPoints(edge: Edge): List[Point] = crossPoints(Line(edge.from, edge.to)).filter(p ⇒ edge.onEdge(p))
    //def crossPoints(line: Line): List[Point]
  }
  case class Edge(from: Point, to: Point) {
    def onEdge(point: Point): Boolean = (to.distanceFrom(point) < tolerance || (math.abs((from.x - to.x) * (point.y - to.y) - (from.y - to.y) * (point.x - to.x)) < tolerance)) && math.min(from.x, to.x) <= point.x && point.x <= math.max(from.x, to.x)
  }
  object Line{
    def apply(a: Point, b: Point): Line = {
      new Line(b.y - a.y, a.x - b.x, b.y * (b.x - a.x) + b.x * (a.y - b.y))
    }
    def apply(p: Point, angle: Angle): Line = {
      new Line(-angle.sin, angle.cos, p.x * angle.sin - p.y * angle.cos)
    }
  }
  case class Line(a: Double, b: Double, c: Double){
    private[this] def isParallel(that: Line): Boolean = {
      math.abs(a * that.b - b * that.a) < tolerance
    }
    def crossPoint(that: Line): Option[Point] = {
      if (isParallel(that)) None
      else Some(Point((b * that.c - that.b * c) / (a * that.b - that.a * b), (c * that.a - that.c * a) / (a * that.b - b * that.a)))
    }
    def distanceFrom(point: Point): Double = {
      math.abs(a * point.x + b * point.y + c) / math.sqrt(a * a + b * b)
    }
  }
  object Angle{
    def apply(line: Line): Angle = {
      val norm = math.sqrt(line.a * line.a + line.b * line.b)
      new Angle(-line.a / norm, line.b / norm)
    }
    def apply(point: Point): Angle = {
      val norm = math.sqrt(point.x * point.x + point.y * point.y)
      new Angle(point.y / norm, point.x / norm)
    }
  }
  case class Angle private (sin: Double, cos: Double) {
    def +(that: Angle): Angle = new Angle(sin * that.cos + cos * that.sin, cos * that.cos - sin * that.sin)
    def -(that: Angle): Angle = new Angle(sin * that.cos - cos * that.sin, cos * that.cos + sin * that.sin)
    def rotate90: Angle = new Angle(-cos, sin)
  }
  case class Point(x: Double, y: Double) {
    def distanceFrom(that: Point): Double = math.sqrt((x - that.x).let(it ⇒ it * it) + (y - that.y).let(it ⇒ it * it))
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
}
