object Main extends App {

  import scala.io.StdIn._
  val Array(n, k) = readLine.trim.split(' ').map(_.toInt)
  val nodes = Array.tabulate(n){_ ⇒ new Node}
  for (_ ← 1 until n){
    val Array(u, v) = readLine.trim.split(' ').map(_.toInt)
    nodes(u - 1).addEdge(nodes(v - 1))
    nodes(v - 1).addEdge(nodes(u - 1))
  }
  countSubTree(nodes(0), k, n)
  val filtered = nodes.filter(_.subTreeOverKCount >= 3)
  println(filtered.length match {
    case 0 ⇒ {
      nodes.find(_.subTreeOverKCount == 2) match {
        case Some(_) if n >= k * 2 + 2 ⇒ 2
        case Some(_) ⇒ 1
        case None ⇒ nodes.find(_.subTreeOverKCount == 1) match {
          case Some(_) if n >= k + 2 ⇒ 1
          case _ ⇒ 0
        }
      }
    }
    case 1 ⇒ {
      val node = nodes.find(_.subTreeOverKCount >= 3).get
      nodes.find(_.subTreeOverKCount == 2) match {
        case Some(_) ⇒ node.subTreeOverKCount
        case None if node.edges.size > node.subTreeOverKCount ⇒ node.subTreeOverKCount
        case _ ⇒ node.subTreeOverKCount - 1
      }
    }
    case _ ⇒ {
      val subRoot = (new Node).also(_.subTreeOverKCount = filtered(0).subTreeOverKCount)
      filtered(0).edges.foreach(makeSubTree(_, filtered(0), subRoot))
      calMaxPath(subRoot)
    }
  })
  def countSubTree(node: Node, k: Int, n: Int): Unit = {
    node.subTreeOverKCount = node.edges.count(next ⇒ countSubTree(next, node, k, n) >= k)
  }
  def countSubTree(node: Node, parent: Node, k: Int, n: Int): Int = {
    node.edges.filter(_ != parent).map{next ⇒
      countSubTree(next, node, k, n)
    }.let{children ⇒
      node.subTreeOverKCount = children.count(_ >= k)
      val sum = children.sum + 1
      if (n - sum >= k) node.subTreeOverKCount += 1
      sum
    }
  }
  def makeSubTree(current: Node, parent: Node, subTree: Node): Unit = {
    if (current.subTreeOverKCount >= 3){
      val next = new Node
      next.subTreeOverKCount = current.subTreeOverKCount
      subTree.addEdge(next)
      next.addEdge(subTree)
      current.edges.withFilter(_ != parent).foreach(n ⇒ makeSubTree(n, current, next))
    }else{
      current.edges.withFilter(_ != parent).foreach(n ⇒ makeSubTree(n, current, subTree))
    }
  }
  def calMaxPath(root: Node): Int = {
    calMaxPath(root, new Node)._2 + 2
  }
  def calMaxPath(node: Node, parent: Node): (Int, Int) = {
    val filtered = node.edges.filter(_ != parent)
    if (filtered.isEmpty){
      (node.subTreeOverKCount - 2, node.subTreeOverKCount - 2)
    }else if (filtered.size == 1){
      val (path, res) = calMaxPath(filtered.head, node)
      if (path + node.subTreeOverKCount - 2 > res) (path + node.subTreeOverKCount - 2, path + node.subTreeOverKCount - 2)
      else (path + node.subTreeOverKCount - 2, res)
    }else {
      val mapped = filtered.map(calMaxPath(_, node))
      val sorted = mapped.map(_._1).toList.sorted(Ordering[Int].reverse)
      val inner = sorted.take(2).sum + node.subTreeOverKCount - 2
      val subInner = mapped.map(_._2).max
      (sorted.head + node.subTreeOverKCount - 2, if (inner > subInner) inner else subInner)
    }
  }
  class Node{
    private var mEdge: List[Node] = Nil
    def addEdge(to: Node): Unit = mEdge ::= to
    def edges: Iterable[Node] = mEdge
    var subTreeOverKCount: Int = 0
  }
  implicit class Scoped[V](val value: V){
    def let[A](func: V ⇒ A): A = func(value)
    def also(func: V ⇒ Unit): V = {
      func(value)
      value
    }
  }
}


Measured memory_bytes: 218776