#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
inline int FIX(int a) { return (a % Mod + Mod) % Mod; }
const int N = 150000 + 5;
int dep[N], dfn[N], fa[N][21], idx = 0, seq[N];
set<int> S;
int n, k;
vector<int> E[N];
void dfs(int rt, int pre, int d) {
  dep[rt] = d;
  dfn[rt] = ++idx;
  seq[idx] = rt;
  fa[rt][0] = pre;
  for (auto &x : E[rt]) {
    if (x != pre) {
      dfs(x, rt, d + 1);
    }
  }
  return;
}
int lca(int u, int v) {
  if (u == v) return v;
  if (dep[u] > dep[v]) swap(u, v);
  int d = dep[v] - dep[u];
  for (int i = 20; i >= 0; i--) {
    if ((((d) >> (i)) & 1ll) == 1) {
      v = fa[v][i];
    }
  }
  for (int i = 20; i >= 0; i--) {
    if (fa[u][i] != fa[v][i]) {
      u = fa[u][i];
      v = fa[v][i];
    }
  }
  return u == v ? u : fa[u][0];
}
int add(int rt) {
  if (S.empty()) return 1;
  int dd = dfn[rt];
  auto it = S.lower_bound(dd);
  int R = seq[it == S.end() ? *S.begin() : *it];
  int L = seq[it == S.begin() ? *S.rbegin() : *(--it)];
  return dep[rt] - dep[lca(rt, L)] - dep[lca(rt, R)] + dep[lca(L, R)];
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    E[a].push_back(b);
    E[b].push_back(a);
  }
  dfs(1, 0, 1);
  for (int p = 1; p <= 20; p++) {
    for (int i = 1; i <= n; i++) {
      fa[i][p] = fa[fa[i][p - 1]][p - 1];
    }
  }
  int all = 0, idx = 1;
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    while (all <= k && idx <= n) {
      all += add(idx);
      S.insert(dfn[idx]);
      if (all <= k)
        ret = max(ret, idx - i + 1);
      else
        break;
      idx++;
    }
    S.erase(dfn[i]);
    all -= add(i);
  }
  cout << ret << endl;
  return 0;
}
