#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int maxd = 20;
int V[maxn << 1], N[maxn << 1], F[maxn], tot = 0;
int num, n, k, L[maxn], R[maxn], p[maxn], fa[maxn][maxd];
int tr[maxn], dep[maxn];
void add(int a, int b) { ++tot, V[tot] = b, N[tot] = F[a], F[a] = tot; }
void dfs(int x, int f, int d) {
  L[x] = ++num, p[num] = x;
  fa[x][0] = f;
  for (int i = 1; i < maxd; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  dep[x] = d;
  for (int p = F[x]; p > 0; p = N[p])
    if (V[p] != f) dfs(V[p], x, d + 1);
  R[x] = num;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int d = maxd - 1; d >= 0; d--)
    if (fa[x][d] != 0 && dep[fa[x][d]] >= dep[y]) x = fa[x][d];
  if (x == y) return x;
  for (int d = maxd - 1; d >= 0; d--)
    if (fa[x][d] != fa[y][d]) {
      x = fa[x][d], y = fa[y][d];
    }
  return fa[x][0];
}
int l = 0, r = 0;
int dist(int a, int b) { return dep[a] + dep[b] - 2 * dep[lca(a, b)]; }
int rt = 0;
void modify(int x, int d) {
  x = L[x];
  for (; x > 0 && x <= n; x += x & -x) tr[x] += d;
}
int sum(int x) {
  int ret = 0;
  for (; x >= 1 && x <= n; x -= x & -x) ret += tr[x];
  return ret;
}
int sumsub(int x) { return sum(R[x]) - sum(L[x] - 1); }
int ins(int x) {
  if (r - l + 1 == 0) {
    modify(x, 1);
    rt = x;
    return 1;
  }
  int y = x;
  for (int d = maxd - 1; d >= 0; d--)
    if (fa[y][d] != 0 && sumsub(fa[y][d]) == 0) y = fa[y][d];
  if (sumsub(y) == 0) y = fa[y][0];
  int ret = 0;
  if (dep[y] < dep[rt]) {
    ret = dist(y, rt) + dist(x, y), rt = y;
  } else
    ret = dist(x, y);
  modify(x, 1);
  return ret;
}
int del(int x, int z) {
  if (r - l + 1 == 1) {
    modify(x, -1);
    rt = 0;
    return 1;
  }
  modify(x, -1);
  int y = x;
  for (int d = maxd - 1; d >= 0; d--)
    if (fa[y][d] != 0 && sumsub(fa[y][d]) <= 0) y = fa[y][d];
  if (sumsub(y) <= 0) y = fa[y][0];
  if (y == rt) {
    y = z;
    int aft = r - l;
    for (int d = maxd - 1; d >= 0; d--)
      if (fa[y][d] != 0 && sumsub(fa[y][d]) < aft) y = fa[y][d];
    if (sumsub(y) < aft) y = fa[y][0];
    rt = y;
    return dist(y, x);
  } else {
    return dist(y, x);
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    add(a, b), add(b, a);
  }
  int ans = 0;
  num = 0;
  dfs(1, 0, 0);
  int sz = 0;
  for (l = 1, r = 0; l <= n; l++) {
    while (true) {
      if (r + 1 > n) break;
      sz += ins(r + 1);
      r++;
      if (sz > k) {
        sz -= del(r, r - 1);
        r--;
        break;
      }
    }
    ans = max(ans, r - l + 1);
    sz -= del(l, l + 1);
  }
  printf("%d\n", ans);
  return 0;
}
