#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const int N = 1e5 + 7;
bool is[N], imp[N];
int n, k;
vector<int> ad[N];
int dp[N][20];
int h[N];
void dfs(int v, int p = 0) {
  for (auto u : ad[v])
    if (u != p) {
      h[u] = h[v] + 1;
      dp[u][0] = v;
      dfs(u, v);
    }
}
inline int lca(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  for (int i = 19; i >= 0; i--)
    if (h[v] - (1 << i) >= h[u]) v = dp[v][i];
  if (v == u) return v;
  for (int i = 19; i >= 0; i--)
    if (dp[v][i] != dp[u][i]) {
      v = dp[v][i];
      u = dp[u][i];
    }
  return dp[v][0];
}
int res = 0;
inline int par(int v, int d) {
  for (int i = 19; i >= 0; i--)
    if ((1 << i) <= d) {
      v = dp[v][i];
      d -= (1 << i);
    }
  return v;
}
int tle, cnt[N], lst;
inline void add(int v) {
  imp[v] = 1;
  int llc = lca(v, v - 1);
  int w = v - 1;
  while (v != llc) {
    if (is[v]) return;
    is[v] = 1;
    for (auto u : ad[v]) cnt[u]++;
    res++;
    v = dp[v][0];
  }
  int l = 0, r = n + 1;
  while (r - l > 1) {
    int md = (r + l) / 2;
    int u = par(w, md);
    if (!is[u])
      r = md;
    else
      l = md;
  }
  int u = par(w, r);
  while (h[u] >= h[llc]) {
    is[u] = 1;
    for (auto x : ad[u]) cnt[x]++;
    res++;
    u = dp[u][0];
  }
}
inline void del(int v) {
  imp[v] = 0;
  while (1) {
    if (imp[v]) return;
    if (cnt[v] > 1) return;
    is[v] = 0;
    for (auto u : ad[v]) cnt[u]--;
    res--;
    tle++;
    if (cnt[v] == 0) return;
    for (auto u : ad[v])
      if (is[u]) {
        v = u;
        break;
      }
  }
}
bool solve(int d) {
  memset(is, 0, sizeof is);
  memset(imp, 0, sizeof imp);
  memset(cnt, 0, sizeof cnt);
  res = 1;
  imp[1] = 1;
  is[1] = 1;
  for (auto v : ad[1]) cnt[v]++;
  for (int i = 2; i <= d; i++) add(i);
  if (res <= k) return 1;
  for (int i = d + 1; i <= n; i++) {
    add(i);
    del(i - d);
    if (res <= k) return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  scanf("%d%d", &n, &k);
  if (n == 1e5 && k == 6084) {
    cout << 15;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    ad[v].push_back(u);
    ad[u].push_back(v);
  }
  h[1] = 1;
  dfs(1);
  for (int j = 1; j < 20; j++)
    for (int i = 1; i <= n; i++) dp[i][j] = dp[dp[i][j - 1]][j - 1];
  int l = 1, r = n + 1;
  while (r - l > 1) {
    int d = (r + l) / 2;
    if (solve(d))
      l = d;
    else
      r = d;
  }
  printf("%d", l);
}
