#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
inline int read() {
  int x(0), w(1);
  char c = getchar();
  while (c ^ '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') w = -1, c = getchar();
  while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return x * w;
}
struct Node {
  int i, d;
};
char opt[2];
int n, K, L, R, Mid, Ans, q, x, y, z, dfs_clock, fa[N][22], dep[N], ans, dfn[N];
int head[N], nxt[N << 1], to[N << 1], cnte;
set<Node> S;
set<Node>::iterator it, it1, it2;
bool operator<(const Node& A, const Node& B) { return A.d < B.d; }
inline void add(int u, int v) {
  to[++cnte] = v;
  nxt[cnte] = head[u];
  head[u] = cnte;
}
void dfs(int u, int Fa) {
  dfn[u] = ++dfs_clock;
  fa[u][0] = Fa;
  for (int i = 1; (1 << i) <= dep[u]; ++i) {
    fa[u][i] = fa[fa[u][i - 1]][i - 1];
  }
  for (int i = head[u]; i; i = nxt[i]) {
    if (to[i] == Fa) continue;
    dep[to[i]] = dep[u] + 1;
    dfs(to[i], u);
  }
}
inline int lca(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  for (int i = 20; i >= 0; --i) {
    if (dep[b] - (1 << i) < dep[a]) continue;
    b = fa[b][i];
  }
  if (a == b) return a;
  for (int i = 20; i >= 0; --i) {
    if (fa[a][i] == fa[b][i]) continue;
    a = fa[a][i], b = fa[b][i];
  }
  return fa[a][0];
}
inline int dis(int a, int b) { return dep[a] + dep[b] - (dep[lca(a, b)] << 1); }
inline void ins(int x) {
  it = S.insert((Node){x, dfn[x]}).first;
  if (S.size() == 1) return;
  it1 = it;
  it2 = it;
  if (it == S.begin()) it1 = S.end();
  --it1;
  ++it2;
  if (it2 == S.end()) it2 = S.begin();
  ans -= dis(it1->i, it2->i);
  ans += dis(it1->i, it->i);
  ans += dis(it->i, it2->i);
}
inline void del(int x) {
  if (S.size() == 1) {
    S.clear();
    ans = 0;
    return;
  }
  it = S.find((Node){x, dfn[x]});
  it1 = it;
  it2 = it;
  if (it == S.begin()) it1 = S.end();
  --it1;
  ++it2;
  if (it2 == S.end()) it2 = S.begin();
  ans -= dis(it1->i, it->i);
  ans -= dis(it->i, it2->i);
  ans += dis(it1->i, it2->i);
  S.erase(it);
}
inline bool judge(int l) {
  S.clear();
  ans = 0;
  for (int i = 1; i <= l; ++i) {
    ins(i);
  }
  if (ans / 2 + 1 <= K) return 1;
  for (int i = l + 1; i <= n; ++i) {
    ins(i);
    del(i - l);
    if (ans / 2 + 1 <= K) return 1;
  }
  return 0;
}
int main() {
  n = read(), K = read();
  for (int i = 1; i < n; ++i) {
    x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dep[1] = 0;
  dfs(1, -1);
  L = 1, R = K;
  while (L <= R) {
    Mid = (L + R) >> 1;
    if (judge(Mid)) {
      L = Mid + 1;
      Ans = Mid;
    } else {
      R = Mid - 1;
    }
  }
  printf("%d\n", Ans);
  return 0;
}
