#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 200;
const int inf = 2e9;
const int mod = 1e9 + 7;
vector<int> adj[maxn];
set<int> st;
int par[20][maxn], t, f[maxn], fp[maxn], h[maxn], ans;
void dfs(int v, int p) {
  f[v] = t;
  fp[t++] = v;
  for (int u : adj[v]) {
    if (u == p) continue;
    par[0][u] = v;
    for (int i = 1; i < 20; i++) {
      par[i][u] = par[i - 1][par[i - 1][u]];
    }
    h[u] = h[v] + 1;
    dfs(u, v);
  }
}
int dis(int u, int v) {
  int res = 0;
  if (h[u] != h[v]) {
    if (h[v] > h[u]) {
      swap(u, v);
    }
    for (int i = 19; i >= 0; i--) {
      if ((h[u] - h[v]) & (1 << i)) {
        u = par[i][u];
        res += (1 << i);
      }
    }
  }
  if (u == v) {
    return res;
  } else {
    for (int i = 19; i >= 0; i--) {
      if (par[i][v] != par[i][u]) {
        res += (1 << i) * 2;
        u = par[i][u];
        v = par[i][v];
      }
    }
  }
  return res + 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  par[0][1] = 1;
  dfs(1, 1);
  int sz = 1;
  int r = 1;
  st.insert(f[1]);
  for (int l = 1; l <= n; l++) {
    if (sz <= k) {
      ans = max(ans, r - l + 1);
    }
    while (sz <= k && r < n) {
      int u, v;
      ans = max(ans, r - l + 1);
      r++;
      if (r > n) continue;
      set<int>::iterator it, last, nxt;
      it = st.lower_bound(f[r]);
      if (it == st.begin() || it == st.end()) {
        last = st.end();
        nxt = st.begin();
        last--;
        v = *last;
        v = fp[v];
        u = *nxt;
        u = fp[u];
      } else {
        u = *it;
        u = fp[u];
        it--;
        v = *it;
        v = fp[v];
      }
      sz += (dis(r, u) + dis(r, v) - dis(u, v)) / 2;
      st.insert(f[r]);
    }
    if (sz <= k) {
      ans = max(ans, r - l + 1);
    }
    set<int>::iterator it, nxt, last;
    last = st.begin();
    nxt = st.end();
    nxt--;
    it = st.lower_bound(f[l]);
    int u, v;
    if (st.size() <= 1) {
      continue;
    }
    if (st.size() == 2) {
      sz = 1;
    } else {
      if (it == last || it == nxt) {
        if (it == last) {
          last++;
        } else {
          nxt--;
        }
      } else {
        last = it;
        nxt = it;
        last--;
        nxt++;
      }
      u = *last;
      u = fp[u];
      v = *nxt;
      v = fp[v];
      sz += (dis(u, v) - dis(u, l) - dis(v, l)) / 2;
    }
    st.erase(f[l]);
  }
  cout << ans;
  return 0;
}
