#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9, lg = 20;
vector<int> g[MAX];
int par[MAX][lg], n, k, h[MAX], l, r, s[MAX], c, in[MAX], ret;
set<int> st;
void dfs(int v, int p = -1) {
  s[v] = c, in[c++] = v;
  for (auto u : g[v])
    if (u != p) {
      h[u] = h[v] + 1, par[u][0] = v;
      for (int i = 1; i < lg; i++) par[u][i] = par[par[u][i - 1]][i - 1];
      dfs(u, v);
    }
}
int parent(int v, int h) {
  for (int i = 0; i < lg; i++)
    if (h >> i & 1) v = par[v][i];
  return v;
}
int lca(int v, int u) {
  if (h[v] > h[u]) swap(v, u);
  u = parent(u, h[u] - h[v]);
  if (v == u) return v;
  for (int i = lg - 1; i >= 0; i--)
    if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];
  return par[v][0];
}
int dis(int v, int u) { return h[v] + h[u] - 2 * h[lca(v, u)]; }
void add(int v) {
  st.insert(s[v]);
  auto it = st.find(s[v]);
  auto itt = it;
  int u, w;
  if (it == st.begin())
    u = in[*st.rbegin()];
  else
    it--, u = in[*it];
  itt++;
  if (itt == st.end())
    w = in[*st.begin()];
  else
    w = in[*itt];
  ret += dis(u, v) + dis(v, w) - dis(u, w);
}
void del(int v) {
  auto it = st.find(s[v]);
  auto itt = it;
  int u, w;
  if (it == st.begin())
    u = in[*st.rbegin()];
  else
    it--, u = in[*it];
  itt++;
  if (itt == st.end())
    w = in[*st.begin()];
  else
    w = in[*itt];
  ret -= dis(u, v) + dis(v, w) - dis(u, w);
  st.erase(s[v]);
}
int check(int l) {
  ret = 0, st.clear();
  int ans = 1e9;
  for (int i = 0; i < l; i++) add(i);
  ans = min(ans, ret);
  for (int i = l; i < n; i++) add(i), del(i - l), ans = min(ans, ret);
  return ans / 2 + 1;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k, r = n + 1;
  for (int i = 1, v, u; i < n; i++)
    cin >> v >> u, v--, u--, g[v].push_back(u), g[u].push_back(v);
  dfs(0);
  while (l < r - 1) {
    int mid = l + r >> 1;
    if (check(mid) <= k)
      l = mid;
    else
      r = mid;
  }
  cout << l;
}
