#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 20, lg = 20;
int n, k, h[N], par[N][lg], in[N], ans, cnt, sz = 2;
vector<int> adj[N];
set<pair<int, int> > st;
void dfs(int v, int p = 0) {
  in[v] = cnt++;
  h[v] = v ? h[p] + 1 : 0;
  par[v][0] = p;
  for (int i = 1; i < lg; i++) par[v][i] = par[par[v][i - 1]][i - 1];
  for (auto u : adj[v]) {
    if (u != p) dfs(u, v);
  }
  return;
}
int go(int v, int len) {
  for (int i = 0; i < lg; i++) {
    if ((1 << i) & len) v = par[v][i];
  }
  return v;
}
int lca(int u, int v) {
  if (h[u] > h[v]) swap(u, v);
  v = go(v, h[v] - h[u]);
  if (u == v) return v;
  for (int i = lg - 1; ~i; i--) {
    if (par[v][i] != par[u][i]) {
      v = par[v][i];
      u = par[u][i];
    }
  }
  return par[v][0];
}
int dist(int u, int v) { return h[u] + h[v] - 2 * h[lca(u, v)]; }
void ins(int x) {
  st.insert({in[x], x});
  set<pair<int, int> >::iterator it = st.find({in[x], x});
  set<pair<int, int> >::iterator nxt = it, prv = it;
  nxt++;
  if (nxt == st.end()) nxt = st.begin();
  if (prv == st.begin()) prv = st.end();
  prv--;
  int a = prv->second, b = nxt->second;
  sz += dist(x, a);
  sz += dist(x, b);
  sz -= dist(a, b);
  return;
}
void rmv(int x) {
  set<pair<int, int> >::iterator it = st.find({in[x], x});
  set<pair<int, int> >::iterator nxt = it, prv = it;
  nxt++;
  if (nxt == st.end()) nxt = st.begin();
  if (prv == st.begin()) prv = st.end();
  prv--;
  int a = prv->second, b = nxt->second;
  sz -= dist(x, a);
  sz -= dist(x, b);
  sz += dist(a, b);
  st.erase(it);
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(0);
  int l = 0, r = -1;
  for (; l < n; l++) {
    if (r < l) {
      ins(l);
      r = l;
    }
    while (r + 1 < n) {
      r++;
      ins(r);
      if (sz > 2 * k) {
        rmv(r);
        r--;
        break;
      }
    }
    ans = max(ans, r - l + 1);
    rmv(l);
  }
  return cout << ans, 0;
}
