#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxn = 100010;
vector<int> a[maxn];
const int LOG = 18;
int par[LOG][maxn];
int tin[maxn];
int dep[maxn];
int tout[maxn];
int timer = 0;
void dfs(int x, int pr) {
  tin[x] = timer++;
  par[0][x] = pr;
  if (pr == -1) par[0][x] = x;
  dep[x] = 0;
  if (pr >= 0) dep[x] = dep[pr] + 1;
  for (int i = 0; i < int((a[x]).size()); ++i) {
    int to = a[x][i];
    if (pr == to) continue;
    dfs(to, x);
  }
  tout[x] = timer++;
}
bool isparent(int x, int y) { return tin[x] <= tin[y] && tout[y] <= tout[x]; }
int lca(int x, int y) {
  if (isparent(x, y)) return x;
  if (isparent(y, x)) return y;
  for (int i = LOG - 1; i >= 0; --i) {
    if (!isparent(par[i][x], y)) x = par[i][x];
  }
  return par[0][x];
}
int getdist(int x, int y) {
  int lc = lca(x, y);
  int res = dep[x] + dep[y] - 2 * dep[lc];
  return res;
}
int curlen = 0;
set<pair<int, int> > st;
int getleft(int v) {
  set<pair<int, int> >::iterator it = st.find(make_pair(tin[v], v));
  if (it == st.begin()) return st.rbegin()->second;
  --it;
  return it->second;
}
int getright(int v) {
  set<pair<int, int> >::iterator it = st.find(make_pair(tin[v], v));
  ++it;
  if (it == st.end()) return st.begin()->second;
  return it->second;
}
void addvertex(int v) {
  st.insert(make_pair(tin[v], v));
  int lf = getleft(v);
  int rg = getright(v);
  curlen += getdist(lf, v) + getdist(v, rg) - getdist(lf, rg);
}
void remvertex(int v) {
  int lf = getleft(v);
  int rg = getright(v);
  curlen -= getdist(lf, v) + getdist(v, rg);
  curlen += getdist(lf, rg);
  assert(st.erase(make_pair(tin[v], v)));
}
const int cinf = 1000000010;
int n;
int calc(int len) {
  st.clear();
  curlen = 0;
  int best = cinf;
  for (int i = 0; i < len; ++i) {
    addvertex(i);
  }
  for (int i = 0; i + len <= n; ++i) {
    best = min(best, curlen);
    if (i + len < n) {
      remvertex(i);
      addvertex(i + len);
    }
  }
  return best / 2 + 1;
}
int main() {
  int k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n - 1; ++i) {
    int fr, to;
    scanf("%d%d", &fr, &to);
    --fr, --to;
    a[fr].push_back(to), a[to].push_back(fr);
  }
  dfs(0, -1);
  for (int i = 1; i < LOG; ++i)
    for (int j = 0; j < n; ++j) par[i][j] = par[i - 1][par[i - 1][j]];
  int l = 0;
  int r = n + 1;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    if (calc(m) <= k)
      l = m;
    else
      r = m;
  }
  printf("%d\n", l);
  return 0;
}
