#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int L = 20;
int h[N], st[N], par[N][L], t, ans;
vector<int> adj[N];
set<pair<int, int> > s;
void dfs(int v, int p) {
  st[v] = t++;
  for (int i = 1; i < L; i++) par[v][i] = par[par[v][i - 1]][i - 1];
  for (int u : adj[v]) {
    if (u == p) continue;
    h[u] = h[v] + 1;
    par[u][0] = v;
    dfs(u, v);
  }
}
int getPar(int v, int k) {
  for (int i = 0; i < L; i++)
    if (k >> i & 1) v = par[v][i];
  return v;
}
int getLca(int u, int v) {
  if (h[v] < h[u]) swap(u, v);
  v = getPar(v, h[v] - h[u]);
  if (u == v) return v;
  for (int i = L - 1; i >= 0; i--)
    if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
  return par[u][0];
}
long long dis(int u, int v) { return h[u] + h[v] - 2 * h[getLca(u, v)]; }
set<pair<int, int> >::iterator prv(set<pair<int, int> >::iterator x) {
  if (x == s.begin()) x = s.end();
  x--;
  return x;
}
set<pair<int, int> >::iterator nxt(set<pair<int, int> >::iterator x) {
  x++;
  if (x == s.end()) x = s.begin();
  return x;
}
void add(int v) {
  if ((int)(s.size()) == 0) {
    s.insert(make_pair(st[v], v));
    return;
  }
  if ((int)(s.size()) == 1) {
    ans = 2 * dis(s.begin()->second, v);
    s.insert(make_pair(st[v], v));
    return;
  }
  set<pair<int, int> >::iterator x, y, z;
  x = s.lower_bound(make_pair(st[v], 0));
  if (x == s.end()) x = s.begin();
  y = prv(x);
  ans -= dis(x->second, y->second);
  s.insert(make_pair(st[v], v));
  x = s.lower_bound(make_pair(st[v], 0));
  y = prv(x);
  z = nxt(x);
  ans += dis(x->second, y->second);
  ans += dis(x->second, z->second);
}
void rem(int v) {
  if ((int)(s.size()) == 1) {
    s.erase(make_pair(st[v], v));
    return;
  }
  if ((int)(s.size()) == 2) {
    ans = 0;
    s.erase(make_pair(st[v], v));
    return;
  }
  set<pair<int, int> >::iterator x, y, z;
  x = s.lower_bound(make_pair(st[v], 0));
  y = prv(x);
  z = nxt(x);
  ans -= dis(x->second, y->second);
  ans -= dis(x->second, z->second);
  s.erase(make_pair(st[v], v));
  x = s.lower_bound(make_pair(st[v], 0));
  if (x == s.end()) x = s.begin();
  y = prv(x);
  ans += dis(x->second, y->second);
}
int main() {
  ios::sync_with_stdio(0);
  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);
  }
  dfs(1, 0);
  int l = 1, r = 1, res = 0;
  for (; r <= n; r++) {
    add(r);
    while (k <= ans / 2) rem(l++);
    res = max(res, r - l + 1);
  }
  cout << res;
  return 0;
}
