#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
const long long maxn = 2e5 + 5, N = 1e8 + 1, SQ = 320, base = 800287,
                mod = 1e9 + 7, INF = 1e9 + 10, lg = 20;
const double eps = 1e-4;
long long n, k, st[maxn], tme, par[maxn][lg], h[maxn];
long long l, r, sz, ans;
vector<long long> edges[maxn];
set<pair<long long, long long> > se;
void dfs(long long v, long long p = -1) {
  st[v] = tme++;
  for (auto u : edges[v]) {
    if (u != p) {
      par[u][0] = v;
      for (long long i = 1; i < lg; ++i) {
        par[u][i] = par[par[u][i - 1]][i - 1];
      }
      h[u] = h[v] + 1;
      dfs(u, v);
    }
  }
}
long long get_par(long long v, long long k) {
  for (long long i = lg - 1; i >= 0; --i) {
    if (k & (1ll << i)) {
      v = par[v][i];
    }
  }
  return v;
}
long long get_lca(long long v, long long u) {
  if (h[v] < h[u]) {
    swap(u, v);
  }
  if (h[v] > h[u]) {
    v = get_par(v, h[v] - h[u]);
  }
  if (v == u) {
    return v;
  }
  for (long long i = lg - 1; i >= 0; --i) {
    if (par[v][i] != par[u][i]) {
      v = par[v][i];
      u = par[u][i];
    }
  }
  return par[v][0];
}
long long get_dist(long long v, long long u) {
  return h[v] + h[u] - 2 * h[get_lca(v, u)];
}
inline void add(long long v) {
  set<pair<long long, long long> >::iterator bef, aft;
  bef = aft = se.upper_bound({st[v], -1});
  if (aft == se.end()) {
    aft--, bef = se.begin();
  } else if (aft == se.begin()) {
    bef = se.end();
    bef--;
  } else {
    bef--;
  }
  long long z1 = bef->second, z2 = aft->second, val = 0;
  val += get_dist(v, z1) + get_dist(v, z2);
  val -= get_dist(z1, z2);
  val /= 2;
  sz += val;
  se.insert({st[v], v});
}
inline void remove(long long v) {
  se.erase({st[v], v});
  set<pair<long long, long long> >::iterator bef, aft;
  bef = aft = se.upper_bound({st[v], -1});
  if (aft == se.end()) {
    aft--, bef = se.begin();
  } else if (aft == se.begin()) {
    bef = se.end();
    bef--;
  } else {
    bef--;
  }
  long long z1 = bef->second, z2 = aft->second, val = 0;
  val += get_dist(v, z1) + get_dist(v, z2);
  val -= get_dist(z1, z2);
  val /= 2;
  sz -= val;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (long long i = 0; i < n - 1; ++i) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  dfs(0);
  se.insert({st[0], 0});
  l = 0, r = 1, sz = 1, ans = 1;
  while (r < n) {
    while (r < n && sz <= k) {
      ans = max(ans, r - l);
      add(r);
      r++;
    }
    while (l < r - 1 && sz > k) {
      remove(l);
      l++;
    }
    ans = max(ans, r - l);
  }
  cout << ans << '\n';
}
