#include <bits/stdc++.h>
using namespace std;
const int N = 100100, M = 200100, P = 20, POW = 17;
int head[N], D[N], dfn[N], f[N][P], ys[N], use[N];
struct Edge {
  int next, go;
  Edge() {}
  Edge(int a, int b) {
    next = a;
    go = b;
  }
  ~Edge() {}
};
Edge edge[M];
set<int> g, gf;
set<int>::iterator it;
int n, k, p = 1, deep;
void build(int a, int b) {
  edge[++p] = Edge(head[a], b);
  head[a] = p;
}
void dfs(int node, int de) {
  D[node] = de;
  dfn[node] = ++deep;
  ys[deep] = node;
  for (int i = head[node]; i; i = edge[i].next)
    if (!D[edge[i].go]) {
      f[edge[i].go][0] = node;
      dfs(edge[i].go, de + 1);
    }
}
void deal() {
  for (int j = 1; j <= POW; j++)
    for (int i = 1; i <= n; i++) f[i][j] = f[f[i][j - 1]][j - 1];
}
int lca(int a, int b) {
  if (D[a] < D[b]) swap(a, b);
  if (!b) return 0;
  int bit = D[a] - D[b];
  for (int i = POW; i >= 0; i--)
    if (bit & (1 << i)) a = f[a][i];
  if (a != b) {
    for (int i = POW; i >= 0; i--)
      if (f[a][i] != f[b][i]) {
        a = f[a][i];
        b = f[b][i];
      }
    return f[a][0];
  } else
    return a;
}
int insert(int op, int u, int& sum) {
  it = g.lower_bound(dfn[u]);
  if (*it == dfn[u]) {
    g.erase(dfn[u]);
    it = g.lower_bound(dfn[u]);
  }
  if (!g.size()) {
    if (op == 1) g.insert(dfn[u]);
    return 0;
  }
  int pre, next;
  if (it == g.begin())
    pre = ys[*(--g.end())];
  else
    pre = ys[*(--it)], it++;
  if (it == g.end())
    next = ys[*g.begin()];
  else
    next = ys[*it];
  int temp = D[u] - D[lca(pre, u)] - D[lca(next, u)] + D[lca(pre, next)];
  if (op == 1)
    sum += temp, g.insert(dfn[u]);
  else
    sum -= temp;
}
int can(int x) {
  g.clear();
  int ans = 0;
  for (int i = 1; i < x; i++) insert(1, i, ans);
  for (int i = x; i <= n; i++) {
    insert(1, i, ans);
    if (ans + 1 <= k) return 1;
    insert(0, i - x + 1, ans);
  }
  return 0;
}
void work() {
  int l = 1, r = k;
  while (l < r) {
    int mid = ((l + r) >> 1) + 1;
    if (can(mid))
      l = mid;
    else
      r = mid - 1;
  }
  printf("%d\n", l);
}
void in() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    build(a, b);
    build(b, a);
  }
  dfs(1, 1);
  deal();
  work();
}
int main() {
  in();
  return 0;
}
