#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
inline void read(long long *a, long long n) {
  for (long long i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
const long long maxn = 1e5 + 10;
const long long maxm = 1e6 + 10;
const long long maxlg = 21;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e18 + 10;
const long long SQ = 317 + 5;
vector<long long> g[maxn];
long long h[maxn], st[maxn], root[maxn][maxlg], cur;
struct cmp {
  inline bool operator()(const long long &a, const long long &b) const {
    return st[a] < st[b];
  }
};
set<long long, cmp> SET;
inline void dfs(long long node, long long fa = 0) {
  h[node] = fa == 0 ? 0 : h[fa] + 1;
  root[node][0] = fa;
  st[node] = cur++;
  for (long long i = 1; i < maxlg; i++)
    root[node][i] = root[root[node][i - 1]][i - 1];
  for (auto u : g[node])
    if (u - fa) dfs(u, node);
}
inline long long lca(long long p, long long q) {
  if (h[p] < h[q]) swap(p, q);
  for (long long i = maxlg - 1; i >= 0; i--)
    if (h[p] - (1 << i) >= h[q]) p = root[p][i];
  if (p == q) return p;
  for (long long i = maxlg - 1; i >= 0; i--)
    if (root[p][i] != root[q][i]) p = root[p][i], q = root[q][i];
  return root[p][0];
}
inline long long dis(long long v, long long u) {
  return h[v] + h[u] - 2 * h[lca(v, u)];
}
inline long long add(long long x, long long fl = 0, long long tp = 0) {
  if (SET.empty() || (SET.size() == 1 && tp == 1)) {
    if (fl) {
      if (tp == 0)
        SET.insert(x);
      else
        SET.erase(x);
    }
    return 1 * (tp == 0 ? 1 : -1);
  }
  long long pre, nxt;
  set<long long>::iterator it, it2;
  it = it2 = SET.upper_bound(x);
  if (it == SET.end()) it = SET.begin();
  if (it2 == SET.begin()) it2 = SET.end();
  it2--;
  if (*it2 == x) {
    if (it2 == SET.begin()) it2 = SET.end();
    it2--;
  }
  pre = *it2, nxt = *it;
  if (fl) {
    if (tp == 0)
      SET.insert(x);
    else
      SET.erase(x);
  }
  return (dis(x, pre) + dis(x, nxt) - dis(pre, nxt)) / 2 * (tp == 0 ? 1 : -1);
}
long long tot;
long long res;
int32_t main() {
  long long n = in(), k = in();
  for (long long i = 0; i < n - 1; i++) {
    long long v = in(), u = in();
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs(1);
  long long r = 1;
  for (long long i = 1; i <= n; i++) {
    while (r <= n && add(r) + tot <= k) tot += add(r++, 1);
    res = max(res, r - i);
    if (r == i) r++;
    tot += add(i, 1, 1);
  }
  cout << res << "\n";
}
