#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20;
const int maxbit = 40;
vector<pair<int, int> > adj[maxn];
set<int> s;
map<int, int> mp;
long long p[maxn][maxbit], t = -1, st[maxn], ft[maxn], res, dist[maxn];
void dfs(int v, int p1 = -1) {
  if (p1 != -1) p[v][0] = p1;
  if (p1 != -1)
    for (int i = 1; i < maxbit; i++) {
      p[v][i] = p[p[v][i - 1]][i - 1];
    }
  st[v] = ++t;
  mp[t] = v;
  for (auto u : adj[v]) {
    if (u.first == p1) continue;
    dist[u.first] = dist[v] + u.second;
    dfs(u.first, v);
  }
  ft[v] = t;
}
bool is_par(int v, int u) {
  if (st[v] <= st[u] && ft[v] >= ft[u]) return 1;
  return 0;
}
int lca(int v, int u) {
  for (int h = maxbit - 1; h >= 0; h--)
    if (!(is_par(p[v][h], u))) {
      v = p[v][h];
    }
  if (is_par(v, u)) return v;
  return p[v][0];
}
long long d(int v, int u) { return dist[v] - dist[lca(v, u)] * 2 + dist[u]; }
void change(int a) {
  if (s.find(st[a]) != s.end()) {
    set<int>::iterator it = s.find(st[a]);
    int u;
    if (it == s.begin()) {
      u = *s.rbegin();
    } else {
      it--;
      u = *it;
      it++;
    }
    u = mp[u];
    res -= d(a, u);
    int u1;
    if (*it != *s.rbegin()) {
      it++;
      u1 = *it;
      it--;
    } else {
      u1 = *s.begin();
    }
    u1 = mp[u1];
    res -= d(a, u1);
    res += d(u, u1);
    s.erase(st[a]);
    return;
  } else {
    s.insert(st[a]);
    set<int>::iterator it = s.find(st[a]);
    int u;
    if (it == s.begin()) {
      u = *s.rbegin();
    } else {
      it--;
      u = *it;
      it++;
    }
    u = mp[u];
    res += d(a, u);
    int u1;
    if (*it != *s.rbegin()) {
      it++;
      u1 = *it;
      it--;
    } else {
      u1 = *s.begin();
    }
    u1 = mp[u1];
    res += d(a, u1);
    res -= d(u, u1);
    return;
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int a, b, c = 1;
    cin >> a >> b;
    adj[--a].push_back({--b, c});
    adj[b].push_back({a, c});
  }
  dfs(0);
  int fr = -1, bck = -1, ans = 0;
  while (fr < n) {
    while (res / 2 >= k) {
      bck++;
      change(bck);
    }
    ans = max(ans, fr - bck);
    fr++;
    change(fr);
  }
  cout << ans;
}
