#include <bits/stdc++.h>
using namespace std;
const int maxn = 100002;
int n, K, dep[maxn], fa[maxn], lca[20][maxn], idx[maxn], dfs_pt;
vector<int> edge[maxn];
void addE(int u, int v) {
  edge[u].push_back(v);
  edge[v].push_back(u);
}
void dfs(int u, int pa = -1) {
  idx[u] = ++dfs_pt;
  for (vector<int>::iterator it = edge[u].begin(); it != edge[u].end(); ++it) {
    int v = *it;
    if (v == pa) continue;
    fa[v] = u, dep[v] = dep[u] + 1;
    dfs(v, u);
  }
}
void initLCA() {
  for (int i = 1; i <= n; ++i) lca[0][i] = fa[i];
  for (int j = 1; j < 20; ++j) {
    for (int i = 1; i <= n; ++i) {
      lca[j][i] = lca[j - 1][lca[j - 1][i]];
    }
  }
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 20 - 1; i >= 0; --i) {
    if (dep[x] - (1 << i) >= dep[y]) x = lca[i][x];
  }
  if (x == y) return x;
  for (int i = 20 - 1; i >= 0; --i) {
    if (lca[i][x] != lca[i][y]) {
      x = lca[i][x], y = lca[i][y];
    }
  }
  return lca[0][x];
}
int dist(int x, int y) {
  int l = LCA(x, y);
  return dep[x] + dep[y] - dep[l] * 2;
}
struct cmp_t {
  bool operator()(const int &a, const int &b) const { return idx[a] < idx[b]; }
};
set<int, cmp_t> in;
int len;
int curNodes() { return len / 2 + 1; }
void add(int u) {
  in.insert(u);
  if (in.size() == 1) return;
  set<int>::iterator it = in.find(u), it_prev, it_succ;
  it_prev = it;
  if (it_prev == in.begin()) it_prev = in.end();
  --it_prev;
  it_succ = it;
  ++it_succ;
  if (it_succ == in.end()) it_succ = in.begin();
  len -= dist(*it_prev, *it_succ);
  len += dist(*it_prev, *it);
  len += dist(*it, *it_succ);
}
void remove(int u) {
  set<int>::iterator it = in.find(u), it_prev, it_succ;
  it_prev = it;
  if (it_prev == in.begin()) it_prev = in.end();
  --it_prev;
  it_succ = it;
  ++it_succ;
  if (it_succ == in.end()) it_succ = in.begin();
  len -= dist(*it_prev, *it);
  len -= dist(*it, *it_succ);
  in.erase(it);
  len += dist(*it_prev, *it_succ);
}
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    addE(u, v);
  }
  dfs(1);
  initLCA();
  int l = 1, answer = 1;
  for (int r = 1; r <= n; ++r) {
    add(r);
    while (l != r && curNodes() > K) {
      remove(l++);
    }
    answer = max(answer, r - l + 1);
  }
  cout << answer << endl;
  return 0;
}
