#include <bits/stdc++.h>
using namespace std;
int n, k, tot, ans, num, sz, ver[200005], nxt[200005], head[100005], lg[100005],
    dfn[100005], b[100005], d[100005], f[20][100005];
set<int> s;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x + (x << 2) << 1) + (ch ^ 48);
  return x * f;
}
void add(int x, int y) { ver[++tot] = y, nxt[tot] = head[x], head[x] = tot; }
void dfs(int x) {
  dfn[x] = ++num, b[num] = x;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = ver[i];
    if (y != f[0][x]) d[y] = d[x] + 1, f[0][y] = x, dfs(y);
  }
}
int lca(int x, int y) {
  if (d[x] < d[y]) swap(x, y);
  for (int i = lg[d[x] - d[y]]; i >= 0; i--)
    if (d[f[i][x]] >= d[y]) x = f[i][x];
  if (x == y) return x;
  for (int i = lg[d[x]]; i >= 0; i--)
    if (f[i][x] != f[i][y]) x = f[i][x], y = f[i][y];
  return f[0][x];
}
int main() {
  n = read(), k = read();
  for (int i = 2; i <= n; i++) {
    int x = read(), y = read();
    add(x, y), add(y, x), lg[i] = lg[i >> 1] + 1;
  }
  d[1] = 1, dfs(1);
  for (int i = 1; i <= lg[n]; i++)
    for (int j = 1; j <= n; j++) f[i][j] = f[i - 1][f[i - 1][j]];
  for (int i = 1, j = 1; i <= n; i++) {
    while (j <= n && sz <= k) {
      ans = max(ans, j - i);
      if (s.empty())
        sz = 1;
      else {
        set<int>::iterator it = s.lower_bound(dfn[j]);
        int x = b[it == s.end() ? *s.begin() : *it],
            y = b[it == s.begin() ? *--s.end() : *--it];
        sz += d[j] + d[lca(x, y)] - d[lca(x, j)] - d[lca(y, j)];
      }
      s.insert(dfn[j]), j++;
    }
    if (sz <= k) ans = max(ans, j - i);
    s.erase(dfn[i]);
    if (s.empty())
      sz = 0;
    else {
      set<int>::iterator it = s.lower_bound(dfn[i]);
      int x = b[it == s.end() ? *s.begin() : *it],
          y = b[it == s.begin() ? *--s.end() : *--it];
      sz += d[lca(x, i)] + d[lca(y, i)] - d[i] - d[lca(x, y)];
    }
  }
  printf("%d", ans);
  return 0;
}
