#include <bits/stdc++.h>
using namespace std;
const int N = 200050, lgN = 20;
int n, K;
namespace T {
struct edge {
  int t, w;
};
vector<edge> e[N];
vector<int> dflist;
long long sd2p[N];
int pre[N][lgN], dep[N];
void link(int x, int y, int w) {
  e[x].push_back((edge){y, w});
  e[y].push_back((edge){x, w});
}
void dfs(int x, int ax, int aw) {
  pre[x][0] = ax;
  dep[x] = dep[ax] + 1;
  for (int i = 1; i < lgN; ++i) pre[x][i] = pre[pre[x][i - 1]][i - 1];
  sd2p[x] = aw + sd2p[ax];
  dflist.push_back(+x);
  for (edge i : e[x])
    if (i.t != ax) dfs(i.t, x, i.w);
}
int LCA(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  for (int i = lgN - 1; i >= 0; --i)
    if (dep[pre[y][i]] >= dep[x]) y = pre[y][i];
  if (x == y) return x;
  for (int i = lgN - 1; i >= 0; --i)
    if (pre[x][i] != pre[y][i]) x = pre[x][i], y = pre[y][i];
  return pre[x][0];
}
long long query(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  int z = LCA(x, y);
  if (z == x)
    return sd2p[y] - sd2p[z];
  else
    return sd2p[x] + sd2p[y] - sd2p[z] * 2LL;
}
}  // namespace T
namespace F {
int prior[N];
struct m_comp {
  bool operator()(int a, int b) { return prior[a] < prior[b]; }
};
set<int, m_comp> l;
long long cur_res;
void add(int x) {
  assert(cur_res % 2 == 0);
  if (l.empty()) {
    l.insert(x);
    return;
  }
  if (l.size() == 1) {
    cur_res = T::query(*l.begin(), x) * 2LL;
    l.insert(x);
    return;
  }
  set<int, m_comp>::iterator isuc = l.upper_bound(x), ipre;
  if (isuc == l.begin() || isuc == l.end())
    ipre = l.begin(), isuc = prev(l.end());
  else
    ipre = prev(isuc);
  cur_res = cur_res - T::query(*ipre, *isuc) + T::query(*ipre, x) +
            T::query(*isuc, x);
  l.insert(x);
}
void remove(int x) {
  assert(cur_res % 2 == 0);
  if (l.size() <= 2) {
    cur_res = 0;
    l.erase(x);
    return;
  }
  set<int, m_comp>::iterator icur = l.find(x), isuc, ipre;
  if (next(icur) == l.end())
    isuc = l.begin(), ipre = prev(icur);
  else if (icur == l.begin())
    isuc = next(icur), ipre = prev(l.end());
  else
    isuc = next(icur), ipre = prev(icur);
  cur_res = cur_res - T::query(x, *ipre) - T::query(x, *isuc) +
            T::query(*ipre, *isuc);
  l.erase(x);
}
void init() {
  T::dfs(1, 0, 0);
  int t = 0;
  for (int i : T::dflist)
    if (i > 0) prior[i] = ++t;
}
}  // namespace F
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 1, a, b; i < n; ++i) {
    scanf("%d%d", &a, &b);
    T::link(a, b, 1);
  }
  F::init();
  F::add(1);
  int res = 0;
  for (int l = 1, r = 1; l <= n; ++l) {
    for (++r; r <= n; ++r) {
      F::add(r);
      if ((F::cur_res >> 1) + 1 > K) {
        F::remove(r);
        break;
      }
    }
    res = max(res, r - l);
    --r;
    F::remove(l);
  }
  printf("%d\n", res);
  return 0;
}
